Ignore:
Timestamp:
Nov 28, 2012, 11:51:48 AM (11 years ago)
Author:
cfuguet
Message:

Modificating the VCI Memory Cache to align the VHDL and the SOCLIB models.
The primary modification consists to add a state DIR_REQ or HEAP_REQ, in all
FSMs using these two structures.

In these states a FSM take the lock of the DIRECTORY or HEAP, respectively,
and at the end of the cycle sends the READ request. Is in the next cycle,
when the response of the READ is obtained.

With this modifications, the behavior of a Synchonous RAM is emulated.

Location:
trunk/modules/vci_mem_cache_v4/caba/source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/vci_mem_cache_v4/caba/source/include/vci_mem_cache_v4.h

    r245 r273  
    2626 *
    2727 * Maintainers: alain eric.guthmuller@polytechnique.edu
    28  */
    29 /*
     28 *              cesar.fuguet-tortolero@lip6.fr
    3029 *
    3130 * Modifications done by Christophe Choichillon on the 7/04/2009:
     
    3332 * - Adding a new VCI target port for the CLEANUP network
    3433 * - Adding new state in the ALLOC_UPT_FSM : ALLOC_UPT_CLEANUP
    35  * 
     34 *
    3635 * Modifications to do :
    3736 * - Adding new variables used by the CLEANUP FSM
     
    5857#include "update_tab_v4.h"
    5958
    60 #define TRANSACTION_TAB_LINES   4               // Number of lines in the transaction tab
    61 #define UPDATE_TAB_LINES        4               // Number of lines in the update tab
     59#define TRANSACTION_TAB_LINES 4 // Number of lines in the transaction tab
     60#define UPDATE_TAB_LINES      4 // Number of lines in the update tab
    6261
    6362namespace soclib {  namespace caba {
     
    8180        TGT_CMD_READ,
    8281        TGT_CMD_WRITE,
    83         TGT_CMD_ATOMIC,
     82        TGT_CMD_ATOMIC
    8483      };
    8584
     
    9796        TGT_RSP_XRAM,
    9897        TGT_RSP_INIT,
    99         TGT_RSP_CLEANUP,
     98        TGT_RSP_CLEANUP
    10099      };
    101100
     
    115114        INIT_CMD_SC_UPDT_INDEX,
    116115        INIT_CMD_SC_UPDT_DATA,
    117         INIT_CMD_SC_UPDT_DATA_HIGH,
     116        INIT_CMD_SC_UPDT_DATA_HIGH
    118117      };
    119118
     
    123122        INIT_RSP_UPT_LOCK,
    124123        INIT_RSP_UPT_CLEAR,
    125         INIT_RSP_END,
     124        INIT_RSP_END
    126125      };
    127126
     
    129128      enum read_fsm_state_e{
    130129        READ_IDLE,
     130        READ_DIR_REQ,
    131131        READ_DIR_LOCK,
    132132        READ_DIR_HIT,
     133        READ_HEAP_REQ,
    133134        READ_HEAP_LOCK,
    134135        READ_HEAP_WRITE,
     
    138139        READ_TRT_LOCK,
    139140        READ_TRT_SET,
    140         READ_TRT_REQ,
     141        READ_TRT_REQ
    141142      };
    142143
     
    145146        WRITE_IDLE,
    146147        WRITE_NEXT,
     148        WRITE_DIR_REQ,
    147149        WRITE_DIR_LOCK,
    148150        WRITE_DIR_READ,
     
    163165        WRITE_BC_CC_SEND,
    164166        WRITE_BC_XRAM_REQ,
    165         WRITE_WAIT,
     167        WRITE_WAIT
    166168      };
    167169
     
    171173        IXR_RSP_ACK,
    172174        IXR_RSP_TRT_ERASE,
    173         IXR_RSP_TRT_READ,
     175        IXR_RSP_TRT_READ
    174176      };
    175177
     
    186188        XRAM_RSP_INVAL,
    187189        XRAM_RSP_WRITE_DIRTY,
     190        XRAM_RSP_HEAP_REQ,
    188191        XRAM_RSP_HEAP_ERASE,
    189192        XRAM_RSP_HEAP_LAST,
    190193        XRAM_RSP_ERROR_ERASE,
    191         XRAM_RSP_ERROR_RSP,
     194        XRAM_RSP_ERROR_RSP
    192195      };
    193196
     
    201204        IXR_CMD_WRITE_NLINE,
    202205        IXR_CMD_SC_NLINE,
    203         IXR_CMD_XRAM_DATA,
     206        IXR_CMD_XRAM_DATA
    204207      };
    205208
     
    207210      enum sc_fsm_state_e{
    208211        SC_IDLE,
     212        SC_DIR_REQ,
    209213        SC_DIR_LOCK,
    210214        SC_DIR_HIT_READ,
     
    224228        SC_MISS_TRT_SET,
    225229        SC_MISS_XRAM_REQ,
    226         SC_WAIT,
     230        SC_WAIT
    227231      };
    228232
     
    230234      enum cleanup_fsm_state_e{
    231235        CLEANUP_IDLE,
     236        CLEANUP_DIR_REQ,
    232237        CLEANUP_DIR_LOCK,
    233238        CLEANUP_DIR_WRITE,
     239        CLEANUP_HEAP_REQ,
    234240        CLEANUP_HEAP_LOCK,
    235241        CLEANUP_HEAP_SEARCH,
     
    239245        CLEANUP_UPT_WRITE,
    240246        CLEANUP_WRITE_RSP,
    241         CLEANUP_RSP,
     247        CLEANUP_RSP
    242248      };
    243249
    244250      /* States of the ALLOC_DIR fsm */
    245251      enum alloc_dir_fsm_state_e{
     252        ALLOC_DIR_RESET,
    246253        ALLOC_DIR_READ,
    247254        ALLOC_DIR_WRITE,
    248255        ALLOC_DIR_SC,
    249256        ALLOC_DIR_CLEANUP,
    250         ALLOC_DIR_XRAM_RSP,
     257        ALLOC_DIR_XRAM_RSP
    251258      };
    252259
     
    257264        ALLOC_TRT_SC,
    258265        ALLOC_TRT_XRAM_RSP,
    259         ALLOC_TRT_IXR_RSP,
     266        ALLOC_TRT_IXR_RSP
    260267      };
    261268
     
    266273        ALLOC_UPT_INIT_RSP,
    267274        ALLOC_UPT_CLEANUP,
    268         ALLOC_UPT_SC,
     275        ALLOC_UPT_SC
    269276      };
    270277
    271278      /* States of the ALLOC_HEAP fsm */
    272279      enum alloc_heap_fsm_state_e{
     280        ALLOC_HEAP_RESET,
    273281        ALLOC_HEAP_READ,
    274282        ALLOC_HEAP_WRITE,
    275283        ALLOC_HEAP_SC,
    276284        ALLOC_HEAP_CLEANUP,
    277         ALLOC_HEAP_XRAM_RSP,
     285        ALLOC_HEAP_XRAM_RSP
    278286      };
    279287
     
    301309
    302310      // instrumentation counters
    303       uint32_t     m_cpt_cycles;            // Counter of cycles
    304       uint32_t     m_cpt_read;              // Number of READ transactions
    305       uint32_t     m_cpt_read_miss;         // Number of MISS READ
    306       uint32_t     m_cpt_write;             // Number of WRITE transactions
    307       uint32_t     m_cpt_write_miss;        // Number of MISS WRITE
    308       uint32_t     m_cpt_write_cells;       // Cumulated length for WRITE transactions
    309       uint32_t     m_cpt_write_dirty;       // Cumulated length for WRITE transactions
    310       uint32_t     m_cpt_update;            // Number of UPDATE transactions
    311       uint32_t     m_cpt_trt_rb;            // Read blocked by a hit in trt
    312       uint32_t     m_cpt_trt_full;          // Transaction blocked due to a full trt
    313       uint32_t     m_cpt_update_mult;       // Number of targets for UPDATE
    314       uint32_t     m_cpt_inval;             // Number of INVAL  transactions
    315       uint32_t     m_cpt_inval_mult;        // Number of targets for INVAL 
    316       uint32_t     m_cpt_inval_brdcast;     // Number of BROADCAST INVAL 
    317       uint32_t     m_cpt_cleanup;           // Number of CLEANUP transactions
    318       uint32_t     m_cpt_ll;                // Number of LL transactions
    319       uint32_t     m_cpt_sc;                // Number of SC transactions
     311      uint32_t     m_cpt_cycles;        // Counter of cycles
     312      uint32_t     m_cpt_read;          // Number of READ transactions
     313      uint32_t     m_cpt_read_miss;     // Number of MISS READ
     314      uint32_t     m_cpt_write;         // Number of WRITE transactions
     315      uint32_t     m_cpt_write_miss;    // Number of MISS WRITE
     316      uint32_t     m_cpt_write_cells;   // Cumulated length for WRITE transactions
     317      uint32_t     m_cpt_write_dirty;   // Cumulated length for WRITE transactions
     318      uint32_t     m_cpt_update;        // Number of UPDATE transactions
     319      uint32_t     m_cpt_trt_rb;        // Read blocked by a hit in trt
     320      uint32_t     m_cpt_trt_full;      // Transaction blocked due to a full trt
     321      uint32_t     m_cpt_update_mult;   // Number of targets for UPDATE
     322      uint32_t     m_cpt_inval;         // Number of INVAL  transactions
     323      uint32_t     m_cpt_inval_mult;    // Number of targets for INVAL
     324      uint32_t     m_cpt_inval_brdcast; // Number of BROADCAST INVAL
     325      uint32_t     m_cpt_cleanup;       // Number of CLEANUP transactions
     326      uint32_t     m_cpt_ll;            // Number of LL transactions
     327      uint32_t     m_cpt_sc;            // Number of SC transactions
    320328
    321329      size_t       m_prev_count;
     
    326334
    327335      public:
    328       sc_in<bool>                                               p_clk;
    329       sc_in<bool>                                               p_resetn;
    330       soclib::caba::VciTarget<vci_param>        p_vci_tgt;
    331       soclib::caba::VciTarget<vci_param>        p_vci_tgt_cleanup;
    332       soclib::caba::VciInitiator<vci_param>     p_vci_ini;     
    333       soclib::caba::VciInitiator<vci_param>     p_vci_ixr;
     336      sc_in<bool>                           p_clk;
     337      sc_in<bool>                           p_resetn;
     338      soclib::caba::VciTarget<vci_param>    p_vci_tgt;
     339      soclib::caba::VciTarget<vci_param>    p_vci_tgt_cleanup;
     340      soclib::caba::VciInitiator<vci_param> p_vci_ini;
     341      soclib::caba::VciInitiator<vci_param> p_vci_ixr;
    334342
    335343      VciMemCacheV4(
    336           sc_module_name name,                                // Instance Name 
     344          sc_module_name name,                                // Instance Name
    337345          const soclib::common::MappingTable &mtp,            // Mapping table for primary requets
    338346          const soclib::common::MappingTable &mtc,            // Mapping table for coherence requets
     
    342350          const soclib::common::IntTab &vci_tgt_index,        // VCI port to PROC (target)
    343351          const soclib::common::IntTab &vci_tgt_index_cleanup,// VCI port to PROC (target) for cleanup
    344           size_t nways,                                       // Number of ways per set 
     352          size_t nways,                                       // Number of ways per set
    345353          size_t nsets,                                       // Number of sets
    346354          size_t nwords,                                      // Number of words per line
     
    348356          size_t transaction_tab_lines=TRANSACTION_TAB_LINES, // Size of the TRT
    349357          size_t update_tab_lines=UPDATE_TAB_LINES,           // Size of the UPT
    350           size_t debug_start_cycle=0,                       
     358          size_t debug_start_cycle=0,
    351359          bool   debug_ok=false);
    352360
     
    366374
    367375      // Component attributes
    368       const size_t                              m_initiators;           // Number of initiators
    369       const size_t                              m_heap_size;            // Size of the heap
    370       const size_t                              m_ways;                 // Number of ways in a set
    371       const size_t                              m_sets;                 // Number of cache sets
    372       const size_t                              m_words;                        // Number of words in a line
    373       const size_t                              m_srcid_ixr;                // Srcid for requests to XRAM
    374       const size_t                              m_srcid_ini;                // Srcid for requests to processors
    375       std::list<soclib::common::Segment>        m_seglist;              // memory cached into the cache
    376       std::list<soclib::common::Segment>        m_cseglist;             // coherence segment for the cache
    377       vci_addr_t                                *m_coherence_table;     // address(srcid)
    378       uint32_t                                  m_transaction_tab_lines;
    379       TransactionTab                            m_transaction_tab;          // xram transaction table
    380       uint32_t                                  m_update_tab_lines;
    381       UpdateTab                                 m_update_tab;               // pending update & invalidate
    382       CacheDirectory                            m_cache_directory;          // data cache directory
    383       HeapDirectory                             m_heap;                 // heap for copies
    384 
    385       data_t                                    ***m_cache_data;            // data array[set][way][word]
     376      std::list<soclib::common::Segment> m_seglist;  // memory cached into the cache
     377      std::list<soclib::common::Segment> m_cseglist; // coherence segment for the cache
     378
     379      const size_t    m_initiators; // Number of initiators
     380      const size_t    m_heap_size;  // Size of the heap
     381      const size_t    m_ways;       // Number of ways in a set
     382      const size_t    m_sets;       // Number of cache sets
     383      const size_t    m_words;      // Number of words in a line
     384      const size_t    m_srcid_ixr;  // Srcid for requests to XRAM
     385      const size_t    m_srcid_ini;  // Srcid for requests to processors
     386
     387      uint32_t        m_transaction_tab_lines;
     388      TransactionTab  m_transaction_tab;  // xram transaction table
     389      uint32_t        m_update_tab_lines;
     390      UpdateTab       m_update_tab;       // pending update & invalidate
     391      CacheDirectory  m_cache_directory;  // data cache directory
     392      HeapDirectory   m_heap;             // heap for copies
     393
     394      data_t      *** m_cache_data;       // data array[set][way][word]
    386395
    387396      // adress masks
    388       const soclib::common::AddressMaskingTable<vci_addr_t>   m_x;
    389       const soclib::common::AddressMaskingTable<vci_addr_t>   m_y;
    390       const soclib::common::AddressMaskingTable<vci_addr_t>   m_z;
    391       const soclib::common::AddressMaskingTable<vci_addr_t>   m_nline;
     397      const soclib::common::AddressMaskingTable<vci_addr_t> m_x;
     398      const soclib::common::AddressMaskingTable<vci_addr_t> m_y;
     399      const soclib::common::AddressMaskingTable<vci_addr_t> m_z;
     400      const soclib::common::AddressMaskingTable<vci_addr_t> m_nline;
    392401
    393402      // broadcast address
    394       vci_addr_t                        m_broadcast_address;
     403      vci_addr_t m_broadcast_address;
    395404
    396405      //////////////////////////////////////////////////
    397406      // Others registers
    398407      //////////////////////////////////////////////////
    399       sc_signal<size_t>   r_copies_limit; // Limit of the number of copies for one line
    400       sc_signal<size_t>   xxx_count;
     408      sc_signal<size_t> r_copies_limit; // Limit of the number of copies for one line
     409      sc_signal<size_t> xxx_count;
    401410
    402411      //////////////////////////////////////////////////
     
    411420      GenericFifo<size_t>    m_cmd_read_pktid_fifo;
    412421
    413       // Fifo between TGT_CMD fsm and WRITE fsm   
     422      // Fifo between TGT_CMD fsm and WRITE fsm
    414423      GenericFifo<uint64_t>  m_cmd_write_addr_fifo;
    415424      GenericFifo<bool>      m_cmd_write_eop_fifo;
     
    418427      GenericFifo<size_t>    m_cmd_write_pktid_fifo;
    419428      GenericFifo<data_t>    m_cmd_write_data_fifo;
    420       GenericFifo<be_t>      m_cmd_write_be_fifo;
     429      GenericFifo<be_t>      m_cmd_write_be_fifo;
    421430
    422431      // Fifo between TGT_CMD fsm and SC fsm
     
    434443      soclib::common::Segment  **m_seg;
    435444      soclib::common::Segment  **m_cseg;
    436 
    437445      ///////////////////////////////////////////////////////
    438446      // Registers controlled by the READ fsm
    439447      ///////////////////////////////////////////////////////
    440448
    441       sc_signal<int>         r_read_fsm;        // FSM state
    442       sc_signal<size_t>      r_read_copy;       // Srcid of the first copy
    443       sc_signal<size_t>      r_read_copy_cache; // Srcid of the first copy
    444       sc_signal<bool>        r_read_copy_inst;  // Type of the first copy
    445       sc_signal<tag_t>       r_read_tag;            // cache line tag (in directory)
    446       sc_signal<bool>        r_read_is_cnt;         // is_cnt bit (in directory)
    447       sc_signal<bool>        r_read_lock;           // lock bit (in directory)
    448       sc_signal<bool>        r_read_dirty;          // dirty bit (in directory)
    449       sc_signal<size_t>      r_read_count;      // number of copies
    450       sc_signal<size_t>      r_read_ptr;        // pointer to the heap
    451       sc_signal<data_t>     *r_read_data;       // data (one cache line)
    452       sc_signal<size_t>      r_read_way;        // associative way (in cache)
    453       sc_signal<size_t>      r_read_trt_index;  // Transaction Table index
    454       sc_signal<size_t>      r_read_next_ptr;   // Next entry to point to
    455       sc_signal<bool>        r_read_last_free;  // Last free entry
    456 
    457       // Buffer between READ fsm and IXR_CMD fsm (ask a missing cache line to XRAM)   
    458       sc_signal<bool>        r_read_to_ixr_cmd_req;     // valid request
    459       sc_signal<addr_t>      r_read_to_ixr_cmd_nline;   // cache line index
    460       sc_signal<size_t>      r_read_to_ixr_cmd_trdid;   // index in Transaction Table
     449      sc_signal<int>      r_read_fsm;        // FSM state
     450      sc_signal<size_t>   r_read_copy;       // Srcid of the first copy
     451      sc_signal<size_t>   r_read_copy_cache; // Srcid of the first copy
     452      sc_signal<bool>     r_read_copy_inst;  // Type of the first copy
     453      sc_signal<tag_t>    r_read_tag;        // cache line tag (in directory)
     454      sc_signal<bool>     r_read_is_cnt;     // is_cnt bit (in directory)
     455      sc_signal<bool>     r_read_lock;       // lock bit (in directory)
     456      sc_signal<bool>     r_read_dirty;      // dirty bit (in directory)
     457      sc_signal<size_t>   r_read_count;      // number of copies
     458      sc_signal<size_t>   r_read_ptr;        // pointer to the heap
     459      sc_signal<data_t> * r_read_data;       // data (one cache line)
     460      sc_signal<size_t>   r_read_way;        // associative way (in cache)
     461      sc_signal<size_t>   r_read_trt_index;  // Transaction Table index
     462      sc_signal<size_t>   r_read_next_ptr;   // Next entry to point to
     463      sc_signal<bool>     r_read_last_free;  // Last free entry
     464
     465      // Buffer between READ fsm and IXR_CMD fsm (ask a missing cache line to XRAM)
     466      sc_signal<bool>     r_read_to_ixr_cmd_req;    // valid request
     467      sc_signal<addr_t>   r_read_to_ixr_cmd_nline;  // cache line index
     468      sc_signal<size_t>   r_read_to_ixr_cmd_trdid;  // index in Transaction Table
    461469
    462470      // Buffer between READ fsm and TGT_RSP fsm (send a hit read response to L1 cache)
    463       sc_signal<bool>      r_read_to_tgt_rsp_req;       // valid request
    464       sc_signal<size_t>    r_read_to_tgt_rsp_srcid;         // Transaction srcid
    465       sc_signal<size_t>    r_read_to_tgt_rsp_trdid;         // Transaction trdid
    466       sc_signal<size_t>    r_read_to_tgt_rsp_pktid;         // Transaction pktid
    467       sc_signal<data_t>   *r_read_to_tgt_rsp_data;          // data (one cache line)
    468       sc_signal<size_t>    r_read_to_tgt_rsp_word;      // first word of the response
    469       sc_signal<size_t>    r_read_to_tgt_rsp_length;    // length of the response
     471      sc_signal<bool>     r_read_to_tgt_rsp_req;    // valid request
     472      sc_signal<size_t>   r_read_to_tgt_rsp_srcid;  // Transaction srcid
     473      sc_signal<size_t>   r_read_to_tgt_rsp_trdid;  // Transaction trdid
     474      sc_signal<size_t>   r_read_to_tgt_rsp_pktid;  // Transaction pktid
     475      sc_signal<data_t> * r_read_to_tgt_rsp_data;   // data (one cache line)
     476      sc_signal<size_t>   r_read_to_tgt_rsp_word;   // first word of the response
     477      sc_signal<size_t>   r_read_to_tgt_rsp_length; // length of the response
    470478
    471479      ///////////////////////////////////////////////////////////////
     
    473481      ///////////////////////////////////////////////////////////////
    474482
    475       sc_signal<int>       r_write_fsm;             // FSM state
    476       sc_signal<addr_t>    r_write_address;         // first word address
    477       sc_signal<size_t>    r_write_word_index;      // first word index in line
    478       sc_signal<size_t>    r_write_word_count;      // number of words in line
    479       sc_signal<size_t>    r_write_srcid;           // transaction srcid
    480       sc_signal<size_t>    r_write_trdid;           // transaction trdid
    481       sc_signal<size_t>    r_write_pktid;           // transaction pktid
    482       sc_signal<data_t>   *r_write_data;            // data (one cache line)   
    483       sc_signal<be_t>     *r_write_be;              // one byte enable per word
    484       sc_signal<bool>      r_write_byte;            // (BE != 0X0) and (BE != 0xF)
    485       sc_signal<bool>      r_write_is_cnt;          // is_cnt bit (in directory)
    486       sc_signal<bool>      r_write_lock;            // lock bit (in directory)
    487       sc_signal<tag_t>     r_write_tag;             // cache line tag (in directory)
    488       sc_signal<size_t>    r_write_copy;            // first owner of the line
    489       sc_signal<size_t>    r_write_copy_cache;      // first owner of the line
    490       sc_signal<bool>      r_write_copy_inst;       // is this owner a ICache ?
    491       sc_signal<size_t>    r_write_count;           // number of copies
    492       sc_signal<size_t>    r_write_ptr;             // pointer to the heap
    493       sc_signal<size_t>    r_write_next_ptr;        // next pointer to the heap
    494       sc_signal<bool>      r_write_to_dec;          // need to decrement update counter
    495       sc_signal<size_t>    r_write_way;                 // way of the line
    496       sc_signal<size_t>    r_write_trt_index;       // index in Transaction Table
    497       sc_signal<size_t>    r_write_upt_index;       // index in Update Table
     483      sc_signal<int>      r_write_fsm;        // FSM state
     484      sc_signal<addr_t>   r_write_address;    // first word address
     485      sc_signal<size_t>   r_write_word_index; // first word index in line
     486      sc_signal<size_t>   r_write_word_count; // number of words in line
     487      sc_signal<size_t>   r_write_srcid;      // transaction srcid
     488      sc_signal<size_t>   r_write_trdid;      // transaction trdid
     489      sc_signal<size_t>   r_write_pktid;      // transaction pktid
     490      sc_signal<data_t> * r_write_data;       // data (one cache line)
     491      sc_signal<be_t>   * r_write_be;         // one byte enable per word
     492      sc_signal<bool>     r_write_byte;       // (BE != 0X0) and (BE != 0xF)
     493      sc_signal<bool>     r_write_is_cnt;     // is_cnt bit (in directory)
     494      sc_signal<bool>     r_write_lock;       // lock bit (in directory)
     495      sc_signal<tag_t>    r_write_tag;        // cache line tag (in directory)
     496      sc_signal<size_t>   r_write_copy;       // first owner of the line
     497      sc_signal<size_t>   r_write_copy_cache; // first owner of the line
     498      sc_signal<bool>     r_write_copy_inst;  // is this owner a ICache ?
     499      sc_signal<size_t>   r_write_count;      // number of copies
     500      sc_signal<size_t>   r_write_ptr;        // pointer to the heap
     501      sc_signal<size_t>   r_write_next_ptr;   // next pointer to the heap
     502      sc_signal<bool>     r_write_to_dec;     // need to decrement update counter
     503      sc_signal<size_t>   r_write_way;        // way of the line
     504      sc_signal<size_t>   r_write_trt_index;  // index in Transaction Table
     505      sc_signal<size_t>   r_write_upt_index;  // index in Update Table
    498506
    499507      // Buffer between WRITE fsm and TGT_RSP fsm (acknowledge a write command from L1)
    500       sc_signal<bool>      r_write_to_tgt_rsp_req;              // valid request
    501       sc_signal<size_t>    r_write_to_tgt_rsp_srcid;    // transaction srcid
    502       sc_signal<size_t>    r_write_to_tgt_rsp_trdid;    // transaction trdid
    503       sc_signal<size_t>    r_write_to_tgt_rsp_pktid;    // transaction pktid
    504 
    505       // Buffer between WRITE fsm and IXR_CMD fsm (ask a missing cache line to XRAM) 
    506       sc_signal<bool>      r_write_to_ixr_cmd_req;      // valid request
    507       sc_signal<bool>      r_write_to_ixr_cmd_write;    // write request
    508       sc_signal<addr_t>    r_write_to_ixr_cmd_nline;    // cache line index
    509       sc_signal<data_t>   *r_write_to_ixr_cmd_data;         // cache line data
    510       sc_signal<size_t>    r_write_to_ixr_cmd_trdid;    // index in Transaction Table
     508      sc_signal<bool>     r_write_to_tgt_rsp_req;   // valid request
     509      sc_signal<size_t>   r_write_to_tgt_rsp_srcid; // transaction srcid
     510      sc_signal<size_t>   r_write_to_tgt_rsp_trdid; // transaction trdid
     511      sc_signal<size_t>   r_write_to_tgt_rsp_pktid; // transaction pktid
     512
     513      // Buffer between WRITE fsm and IXR_CMD fsm (ask a missing cache line to XRAM)
     514      sc_signal<bool>     r_write_to_ixr_cmd_req;   // valid request
     515      sc_signal<bool>     r_write_to_ixr_cmd_write; // write request
     516      sc_signal<addr_t>   r_write_to_ixr_cmd_nline; // cache line index
     517      sc_signal<data_t> * r_write_to_ixr_cmd_data;  // cache line data
     518      sc_signal<size_t>   r_write_to_ixr_cmd_trdid; // index in Transaction Table
    511519
    512520      // Buffer between WRITE fsm and INIT_CMD fsm (Update/Invalidate L1 caches)
    513       sc_signal<bool>      r_write_to_init_cmd_multi_req;   // valid multicast request
    514       sc_signal<bool>      r_write_to_init_cmd_brdcast_req; // valid brdcast request
    515       sc_signal<addr_t>    r_write_to_init_cmd_nline;       // cache line index
    516       sc_signal<size_t>    r_write_to_init_cmd_trdid;       // index in Update Table
    517       sc_signal<data_t>   *r_write_to_init_cmd_data;        // data (one cache line)
    518       sc_signal<be_t>     *r_write_to_init_cmd_be;              // word enable
    519       sc_signal<size_t>    r_write_to_init_cmd_count;       // number of words in line
    520       sc_signal<size_t>    r_write_to_init_cmd_index;       // index of first word in line
    521       GenericFifo<bool>    m_write_to_init_cmd_inst_fifo;   // fifo for the L1 type
    522       GenericFifo<size_t>  m_write_to_init_cmd_srcid_fifo;  // fifo for srcids
    523       GenericFifo<size_t>  m_write_to_init_cmd_cache_id_fifo; // fifo for srcids
     521      sc_signal<bool>     r_write_to_init_cmd_multi_req;     // valid multicast request
     522      sc_signal<bool>     r_write_to_init_cmd_brdcast_req;  // valid brdcast request
     523      sc_signal<addr_t>   r_write_to_init_cmd_nline;         // cache line index
     524      sc_signal<size_t>   r_write_to_init_cmd_trdid;         // index in Update Table
     525      sc_signal<data_t> * r_write_to_init_cmd_data;          // data (one cache line)
     526      sc_signal<be_t>   * r_write_to_init_cmd_be;            // word enable
     527      sc_signal<size_t>   r_write_to_init_cmd_count;         // number of words in line
     528      sc_signal<size_t>   r_write_to_init_cmd_index;         // index of first word in line
     529      GenericFifo<bool>   m_write_to_init_cmd_inst_fifo;     // fifo for the L1 type
     530      GenericFifo<size_t> m_write_to_init_cmd_srcid_fifo;    // fifo for srcids
     531      GenericFifo<size_t> m_write_to_init_cmd_cache_id_fifo; // fifo for srcids
    524532
    525533      // Buffer between WRITE fsm and INIT_RSP fsm (Decrement UPT entry)
    526       sc_signal<bool>      r_write_to_init_rsp_req;         // valid request
    527       sc_signal<size_t>    r_write_to_init_rsp_upt_index;  // index in update table
     534      sc_signal<bool>     r_write_to_init_rsp_req;       // valid request
     535      sc_signal<size_t>   r_write_to_init_rsp_upt_index; // index in update table
    528536
    529537      /////////////////////////////////////////////////////////
     
    531539      //////////////////////////////////////////////////////////
    532540
    533       sc_signal<int>       r_init_rsp_fsm;        // FSM state
    534       sc_signal<size_t>    r_init_rsp_upt_index; // index in the Update Table
    535       sc_signal<size_t>    r_init_rsp_srcid;      // pending write srcid     
    536       sc_signal<size_t>    r_init_rsp_trdid;      // pending write trdid     
    537       sc_signal<size_t>    r_init_rsp_pktid;      // pending write pktid     
    538       sc_signal<addr_t>    r_init_rsp_nline;      // pending write nline     
     541      sc_signal<int>      r_init_rsp_fsm;       // FSM state
     542      sc_signal<size_t>   r_init_rsp_upt_index; // index in the Update Table
     543      sc_signal<size_t>   r_init_rsp_srcid;     // pending write srcid
     544      sc_signal<size_t>   r_init_rsp_trdid;     // pending write trdid
     545      sc_signal<size_t>   r_init_rsp_pktid;     // pending write pktid
     546      sc_signal<addr_t>   r_init_rsp_nline;     // pending write nline
    539547
    540548      // Buffer between INIT_RSP fsm and TGT_RSP fsm (complete write/update transaction)
    541       sc_signal<bool>      r_init_rsp_to_tgt_rsp_req;           // valid request
    542       sc_signal<size_t>    r_init_rsp_to_tgt_rsp_srcid;         // Transaction srcid
    543       sc_signal<size_t>    r_init_rsp_to_tgt_rsp_trdid;         // Transaction trdid
    544       sc_signal<size_t>    r_init_rsp_to_tgt_rsp_pktid;         // Transaction pktid
     549      sc_signal<bool>     r_init_rsp_to_tgt_rsp_req;   // valid request
     550      sc_signal<size_t>   r_init_rsp_to_tgt_rsp_srcid; // Transaction srcid
     551      sc_signal<size_t>   r_init_rsp_to_tgt_rsp_trdid; // Transaction trdid
     552      sc_signal<size_t>   r_init_rsp_to_tgt_rsp_pktid; // Transaction pktid
    545553
    546554      ///////////////////////////////////////////////////////
     
    548556      ///////////////////////////////////////////////////////
    549557
    550       sc_signal<int>         r_cleanup_fsm;         // FSM state
    551       sc_signal<size_t>      r_cleanup_srcid;       // transaction srcid
    552       sc_signal<size_t>      r_cleanup_trdid;       // transaction trdid
    553       sc_signal<size_t>      r_cleanup_pktid;       // transaction pktid
    554       sc_signal<addr_t>      r_cleanup_nline;       // cache line index
    555 
    556       sc_signal<copy_t>      r_cleanup_copy;        // first copy
    557       sc_signal<copy_t>      r_cleanup_copy_cache;  // first copy
    558       sc_signal<size_t>      r_cleanup_copy_inst;   // type of the first copy
    559       sc_signal<copy_t>      r_cleanup_count;       // number of copies
    560       sc_signal<size_t>      r_cleanup_ptr;         // pointer to the heap
    561       sc_signal<size_t>      r_cleanup_prev_ptr;    // previous pointer to the heap
    562       sc_signal<size_t>      r_cleanup_prev_srcid;  // srcid of previous heap entry
    563       sc_signal<size_t>      r_cleanup_prev_cache_id; // srcid of previous heap entry
    564       sc_signal<bool>        r_cleanup_prev_inst;   // inst bit of previous heap entry
    565       sc_signal<size_t>      r_cleanup_next_ptr;    // next pointer to the heap
    566       sc_signal<tag_t>       r_cleanup_tag;             // cache line tag (in directory)
    567       sc_signal<bool>        r_cleanup_is_cnt;      // inst bit (in directory)
    568       sc_signal<bool>        r_cleanup_lock;        // lock bit (in directory)
    569       sc_signal<bool>        r_cleanup_dirty;       // dirty bit (in directory)
    570       sc_signal<size_t>      r_cleanup_way;             // associative way (in cache)
    571 
    572       sc_signal<size_t>      r_cleanup_write_srcid; // srcid of write response
    573       sc_signal<size_t>      r_cleanup_write_trdid; // trdid of write rsp
    574       sc_signal<size_t>      r_cleanup_write_pktid; // pktid of write rsp
    575       sc_signal<bool>        r_cleanup_need_rsp;    // needs a write rsp
    576 
    577       sc_signal<size_t>      r_cleanup_index;       // index of the INVAL line (in the UPT)
     558      sc_signal<int>      r_cleanup_fsm;           // FSM state
     559      sc_signal<size_t>   r_cleanup_srcid;         // transaction srcid
     560      sc_signal<size_t>   r_cleanup_trdid;         // transaction trdid
     561      sc_signal<size_t>   r_cleanup_pktid;         // transaction pktid
     562      sc_signal<addr_t>   r_cleanup_nline;         // cache line index
     563
     564      sc_signal<copy_t>   r_cleanup_copy;          // first copy
     565      sc_signal<copy_t>   r_cleanup_copy_cache;    // first copy
     566      sc_signal<size_t>   r_cleanup_copy_inst;     // type of the first copy
     567      sc_signal<copy_t>   r_cleanup_count;         // number of copies
     568      sc_signal<size_t>   r_cleanup_ptr;           // pointer to the heap
     569      sc_signal<size_t>   r_cleanup_prev_ptr;      // previous pointer to the heap
     570      sc_signal<size_t>   r_cleanup_prev_srcid;    // srcid of previous heap entry
     571      sc_signal<size_t>   r_cleanup_prev_cache_id; // srcid of previous heap entry
     572      sc_signal<bool>     r_cleanup_prev_inst;     // inst bit of previous heap entry
     573      sc_signal<size_t>   r_cleanup_next_ptr;      // next pointer to the heap
     574      sc_signal<tag_t>    r_cleanup_tag;           // cache line tag (in directory)
     575      sc_signal<bool>     r_cleanup_is_cnt;        // inst bit (in directory)
     576      sc_signal<bool>     r_cleanup_lock;          // lock bit (in directory)
     577      sc_signal<bool>     r_cleanup_dirty;         // dirty bit (in directory)
     578      sc_signal<size_t>   r_cleanup_way;           // associative way (in cache)
     579
     580      sc_signal<size_t>   r_cleanup_write_srcid;  // srcid of write response
     581      sc_signal<size_t>   r_cleanup_write_trdid;  // trdid of write rsp
     582      sc_signal<size_t>   r_cleanup_write_pktid;  // pktid of write rsp
     583      sc_signal<bool>     r_cleanup_need_rsp;      // needs a write rsp
     584
     585      sc_signal<size_t>   r_cleanup_index;         // index of the INVAL line (in the UPT)
    578586
    579587      // Buffer between CLEANUP fsm and TGT_RSP fsm (acknowledge a write command from L1)
    580       sc_signal<bool>      r_cleanup_to_tgt_rsp_req;    // valid request
    581       sc_signal<size_t>    r_cleanup_to_tgt_rsp_srcid; // transaction srcid
    582       sc_signal<size_t>    r_cleanup_to_tgt_rsp_trdid;  // transaction trdid
    583       sc_signal<size_t>    r_cleanup_to_tgt_rsp_pktid;  // transaction pktid
     588      sc_signal<bool>     r_cleanup_to_tgt_rsp_req;   // valid request
     589      sc_signal<size_t>   r_cleanup_to_tgt_rsp_srcid; // transaction srcid
     590      sc_signal<size_t>   r_cleanup_to_tgt_rsp_trdid; // transaction trdid
     591      sc_signal<size_t>   r_cleanup_to_tgt_rsp_pktid; // transaction pktid
    584592
    585593      ///////////////////////////////////////////////////////
     
    587595      ///////////////////////////////////////////////////////
    588596
    589       sc_signal<int>       r_sc_fsm;                        // FSM state
    590       sc_signal<data_t>    r_sc_wdata;                      // write data word
    591       sc_signal<data_t>    *r_sc_rdata;                     // read data word
    592       sc_signal<uint32_t>  r_sc_lfsr;                       // lfsr for random introducing
    593       sc_signal<size_t>    r_sc_cpt;                        // size of command
    594       sc_signal<copy_t>    r_sc_copy;                       // Srcid of the first copy
    595       sc_signal<copy_t>    r_sc_copy_cache;                // Srcid of the first copy
    596       sc_signal<bool>      r_sc_copy_inst;                      // Type of the first copy
    597       sc_signal<size_t>    r_sc_count;                      // number of copies
    598       sc_signal<size_t>    r_sc_ptr;                        // pointer to the heap
    599       sc_signal<size_t>    r_sc_next_ptr;                       // next pointer to the heap
    600       sc_signal<bool>      r_sc_is_cnt;                     // is_cnt bit (in directory)
    601       sc_signal<bool>      r_sc_dirty;                      // dirty bit (in directory)
    602       sc_signal<size_t>    r_sc_way;                            // way in directory
    603       sc_signal<size_t>    r_sc_set;                            // set in directory
    604       sc_signal<data_t>    r_sc_tag;                            // cache line tag (in directory)
    605       sc_signal<size_t>    r_sc_trt_index;                  // Transaction Table index
    606       sc_signal<size_t>    r_sc_upt_index;                  // Update Table index
    607 
    608       // Buffer between SC fsm and INIT_CMD fsm (XRAM read)     
    609       sc_signal<bool>      r_sc_to_ixr_cmd_req;             // valid request
    610       sc_signal<addr_t>    r_sc_to_ixr_cmd_nline;          // cache line index
    611       sc_signal<size_t>    r_sc_to_ixr_cmd_trdid;          // index in Transaction Table
    612       sc_signal<bool>      r_sc_to_ixr_cmd_write;          // write request
    613       sc_signal<data_t>   *r_sc_to_ixr_cmd_data;            // cache line data
     597      sc_signal<int>      r_sc_fsm;        // FSM state
     598      sc_signal<data_t>   r_sc_wdata;      // write data word
     599      sc_signal<data_t> * r_sc_rdata;      // read data word
     600      sc_signal<uint32_t> r_sc_lfsr;       // lfsr for random introducing
     601      sc_signal<size_t>   r_sc_cpt;        // size of command
     602      sc_signal<copy_t>   r_sc_copy;       // Srcid of the first copy
     603      sc_signal<copy_t>   r_sc_copy_cache; // Srcid of the first copy
     604      sc_signal<bool>     r_sc_copy_inst;  // Type of the first copy
     605      sc_signal<size_t>   r_sc_count;      // number of copies
     606      sc_signal<size_t>   r_sc_ptr;        // pointer to the heap
     607      sc_signal<size_t>   r_sc_next_ptr;   // next pointer to the heap
     608      sc_signal<bool>     r_sc_is_cnt;     // is_cnt bit (in directory)
     609      sc_signal<bool>     r_sc_dirty;      // dirty bit (in directory)
     610      sc_signal<size_t>   r_sc_way;        // way in directory
     611      sc_signal<size_t>   r_sc_set;        // set in directory
     612      sc_signal<data_t>   r_sc_tag;        // cache line tag (in directory)
     613      sc_signal<size_t>   r_sc_trt_index;  // Transaction Table index
     614      sc_signal<size_t>   r_sc_upt_index;  // Update Table index
     615
     616      // Buffer between SC fsm and INIT_CMD fsm (XRAM read)
     617      sc_signal<bool>     r_sc_to_ixr_cmd_req;   // valid request
     618      sc_signal<addr_t>   r_sc_to_ixr_cmd_nline; // cache line index
     619      sc_signal<size_t>   r_sc_to_ixr_cmd_trdid; // index in Transaction Table
     620      sc_signal<bool>     r_sc_to_ixr_cmd_write; // write request
     621      sc_signal<data_t> * r_sc_to_ixr_cmd_data;  // cache line data
    614622
    615623
    616624      // Buffer between SC fsm and TGT_RSP fsm
    617       sc_signal<bool>      r_sc_to_tgt_rsp_req;             // valid request
    618       sc_signal<data_t>    r_sc_to_tgt_rsp_data;            // read data word
    619       sc_signal<size_t>    r_sc_to_tgt_rsp_srcid;          // Transaction srcid
    620       sc_signal<size_t>    r_sc_to_tgt_rsp_trdid;          // Transaction trdid
    621       sc_signal<size_t>    r_sc_to_tgt_rsp_pktid;          // Transaction pktid
     625      sc_signal<bool>     r_sc_to_tgt_rsp_req;   // valid request
     626      sc_signal<data_t>   r_sc_to_tgt_rsp_data;  // read data word
     627      sc_signal<size_t>   r_sc_to_tgt_rsp_srcid; // Transaction srcid
     628      sc_signal<size_t>   r_sc_to_tgt_rsp_trdid; // Transaction trdid
     629      sc_signal<size_t>   r_sc_to_tgt_rsp_pktid; // Transaction pktid
    622630
    623631      // Buffer between SC fsm and INIT_CMD fsm (Update/Invalidate L1 caches)
    624       sc_signal<bool>      r_sc_to_init_cmd_multi_req;      // valid request
    625       sc_signal<bool>      r_sc_to_init_cmd_brdcast_req;    // brdcast request
    626       sc_signal<addr_t>    r_sc_to_init_cmd_nline;              // cache line index
    627       sc_signal<size_t>    r_sc_to_init_cmd_trdid;              // index in Update Table
    628       sc_signal<data_t>    r_sc_to_init_cmd_wdata;          // data (one word)
    629       sc_signal<bool>      r_sc_to_init_cmd_is_long;        // it is a 64 bits SC
    630       sc_signal<data_t>    r_sc_to_init_cmd_wdata_high;     // data high (one word)
    631       sc_signal<size_t>    r_sc_to_init_cmd_index;              // index of the word in line
    632       GenericFifo<bool>    m_sc_to_init_cmd_inst_fifo;      // fifo for the L1 type
    633       GenericFifo<size_t>  m_sc_to_init_cmd_srcid_fifo;     // fifo for srcids
    634       GenericFifo<size_t>  m_sc_to_init_cmd_cache_id_fifo; // fifo for srcids
     632      sc_signal<bool>     r_sc_to_init_cmd_multi_req;     // valid request
     633      sc_signal<bool>     r_sc_to_init_cmd_brdcast_req;   // brdcast request
     634      sc_signal<addr_t>   r_sc_to_init_cmd_nline;         // cache line index
     635      sc_signal<size_t>   r_sc_to_init_cmd_trdid;         // index in Update Table
     636      sc_signal<data_t>   r_sc_to_init_cmd_wdata;         // data (one word)
     637      sc_signal<bool>     r_sc_to_init_cmd_is_long;       // it is a 64 bits SC
     638      sc_signal<data_t>   r_sc_to_init_cmd_wdata_high;    // data high (one word)
     639      sc_signal<size_t>   r_sc_to_init_cmd_index;         // index of the word in line
     640      GenericFifo<bool>   m_sc_to_init_cmd_inst_fifo;     // fifo for the L1 type
     641      GenericFifo<size_t> m_sc_to_init_cmd_srcid_fifo;    // fifo for srcids
     642      GenericFifo<size_t> m_sc_to_init_cmd_cache_id_fifo; // fifo for srcids
    635643
    636644      // Buffer between SC fsm and INIT_RSP fsm (Decrement UPT entry)
    637       sc_signal<bool>      r_sc_to_init_rsp_req;            // valid request
    638       sc_signal<size_t>    r_sc_to_init_rsp_upt_index;      // index in update table
     645      sc_signal<bool>     r_sc_to_init_rsp_req;       // valid request
     646      sc_signal<size_t>   r_sc_to_init_rsp_upt_index; // index in update table
    639647
    640648      ////////////////////////////////////////////////////
     
    642650      ////////////////////////////////////////////////////
    643651
    644       sc_signal<int>       r_ixr_rsp_fsm;       // FSM state
    645       sc_signal<size_t>    r_ixr_rsp_trt_index; // TRT entry index
    646       sc_signal<size_t>    r_ixr_rsp_cpt;           // word counter
     652      sc_signal<int>      r_ixr_rsp_fsm;       // FSM state
     653      sc_signal<size_t>   r_ixr_rsp_trt_index; // TRT entry index
     654      sc_signal<size_t>   r_ixr_rsp_cpt;       // word counter
    647655
    648656      // Buffer between IXR_RSP fsm and XRAM_RSP fsm  (response from the XRAM)
    649       sc_signal<bool>     *r_ixr_rsp_to_xram_rsp_rok;   // A xram response is ready
     657      sc_signal<bool>   * r_ixr_rsp_to_xram_rsp_rok; // A xram response is ready
    650658
    651659      ////////////////////////////////////////////////////
     
    653661      ////////////////////////////////////////////////////
    654662
    655       sc_signal<int>       r_xram_rsp_fsm;                      // FSM state
    656       sc_signal<size_t>    r_xram_rsp_trt_index;            // TRT entry index
    657       TransactionTabEntry  r_xram_rsp_trt_buf;              // TRT entry local buffer
    658       sc_signal<bool>      r_xram_rsp_victim_inval;         // victim line invalidate
    659       sc_signal<bool>      r_xram_rsp_victim_is_cnt;    // victim line inst bit
    660       sc_signal<bool>      r_xram_rsp_victim_dirty;         // victim line dirty bit
    661       sc_signal<size_t>    r_xram_rsp_victim_way;           // victim line way
    662       sc_signal<size_t>    r_xram_rsp_victim_set;           // victim line set
    663       sc_signal<addr_t>    r_xram_rsp_victim_nline;     // victim line index
    664       sc_signal<copy_t>    r_xram_rsp_victim_copy;      // victim line first copy
    665       sc_signal<copy_t>    r_xram_rsp_victim_copy_cache;// victim line first copy
    666       sc_signal<bool>      r_xram_rsp_victim_copy_inst; // victim line type of first copy
    667       sc_signal<size_t>    r_xram_rsp_victim_count;         // victim line number of copies
    668       sc_signal<size_t>    r_xram_rsp_victim_ptr;       // victim line pointer to the heap
    669       sc_signal<data_t>   *r_xram_rsp_victim_data;          // victim line data
    670       sc_signal<size_t>    r_xram_rsp_upt_index;            // UPT entry index
    671       sc_signal<size_t>    r_xram_rsp_next_ptr;         // Next pointer to the heap
     663      sc_signal<int>      r_xram_rsp_fsm;               // FSM state
     664      sc_signal<size_t>   r_xram_rsp_trt_index;         // TRT entry index
     665      TransactionTabEntry r_xram_rsp_trt_buf;           // TRT entry local buffer
     666      sc_signal<bool>     r_xram_rsp_victim_inval;      // victim line invalidate
     667      sc_signal<bool>     r_xram_rsp_victim_is_cnt;     // victim line inst bit
     668      sc_signal<bool>     r_xram_rsp_victim_dirty;      // victim line dirty bit
     669      sc_signal<size_t>   r_xram_rsp_victim_way;        // victim line way
     670      sc_signal<size_t>   r_xram_rsp_victim_set;        // victim line set
     671      sc_signal<addr_t>   r_xram_rsp_victim_nline;      // victim line index
     672      sc_signal<copy_t>   r_xram_rsp_victim_copy;       // victim line first copy
     673      sc_signal<copy_t>   r_xram_rsp_victim_copy_cache; // victim line first copy
     674      sc_signal<bool>     r_xram_rsp_victim_copy_inst;  // victim line type of first copy
     675      sc_signal<size_t>   r_xram_rsp_victim_count;      // victim line number of copies
     676      sc_signal<size_t>   r_xram_rsp_victim_ptr;        // victim line pointer to the heap
     677      sc_signal<data_t> * r_xram_rsp_victim_data;       // victim line data
     678      sc_signal<size_t>   r_xram_rsp_upt_index;         // UPT entry index
     679      sc_signal<size_t>   r_xram_rsp_next_ptr;          // Next pointer to the heap
    672680
    673681      // Buffer between XRAM_RSP fsm and TGT_RSP fsm  (response to L1 cache)
    674       sc_signal<bool>      r_xram_rsp_to_tgt_rsp_req;   // Valid request
    675       sc_signal<size_t>    r_xram_rsp_to_tgt_rsp_srcid; // Transaction srcid
    676       sc_signal<size_t>    r_xram_rsp_to_tgt_rsp_trdid; // Transaction trdid
    677       sc_signal<size_t>    r_xram_rsp_to_tgt_rsp_pktid; // Transaction pktid
    678       sc_signal<data_t>   *r_xram_rsp_to_tgt_rsp_data;  // data (one cache line)
    679       sc_signal<size_t>    r_xram_rsp_to_tgt_rsp_word;  // first word index
    680       sc_signal<size_t>    r_xram_rsp_to_tgt_rsp_length;// length of the response
    681       sc_signal<bool>      r_xram_rsp_to_tgt_rsp_rerror;// send error to requester
    682 
    683       // Buffer between XRAM_RSP fsm and INIT_CMD fsm (Inval L1 Caches) 
    684       sc_signal<bool>       r_xram_rsp_to_init_cmd_multi_req;       // Valid request
    685       sc_signal<bool>       r_xram_rsp_to_init_cmd_brdcast_req;     // Broadcast request
    686       sc_signal<addr_t>     r_xram_rsp_to_init_cmd_nline;           // cache line index;
    687       sc_signal<size_t>     r_xram_rsp_to_init_cmd_trdid;           // index of UPT entry
    688       GenericFifo<bool>     m_xram_rsp_to_init_cmd_inst_fifo;       // fifo for the L1 type
    689       GenericFifo<size_t>   m_xram_rsp_to_init_cmd_srcid_fifo;      // fifo for srcids
    690       GenericFifo<size_t>   m_xram_rsp_to_init_cmd_cache_id_fifo;      // fifo for srcids
     682      sc_signal<bool>     r_xram_rsp_to_tgt_rsp_req;    // Valid request
     683      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_srcid;  // Transaction srcid
     684      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_trdid;  // Transaction trdid
     685      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_pktid;  // Transaction pktid
     686      sc_signal<data_t> * r_xram_rsp_to_tgt_rsp_data;   // data (one cache line)
     687      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_word;   // first word index
     688      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_length; // length of the response
     689      sc_signal<bool>     r_xram_rsp_to_tgt_rsp_rerror; // send error to requester
     690
     691      // Buffer between XRAM_RSP fsm and INIT_CMD fsm (Inval L1 Caches)
     692      sc_signal<bool>     r_xram_rsp_to_init_cmd_multi_req;     // Valid request
     693      sc_signal<bool>     r_xram_rsp_to_init_cmd_brdcast_req;   // Broadcast request
     694      sc_signal<addr_t>   r_xram_rsp_to_init_cmd_nline;         // cache line index;
     695      sc_signal<size_t>   r_xram_rsp_to_init_cmd_trdid;         // index of UPT entry
     696      GenericFifo<bool>   m_xram_rsp_to_init_cmd_inst_fifo;     // fifo for the L1 type
     697      GenericFifo<size_t> m_xram_rsp_to_init_cmd_srcid_fifo;    // fifo for srcids
     698      GenericFifo<size_t> m_xram_rsp_to_init_cmd_cache_id_fifo; // fifo for srcids
    691699
    692700      // Buffer between XRAM_RSP fsm and IXR_CMD fsm (XRAM write)
    693       sc_signal<bool>      r_xram_rsp_to_ixr_cmd_req;   // Valid request
    694       sc_signal<addr_t>    r_xram_rsp_to_ixr_cmd_nline; // cache line index
    695       sc_signal<data_t>   *r_xram_rsp_to_ixr_cmd_data;  // cache line data
    696       sc_signal<size_t>    r_xram_rsp_to_ixr_cmd_trdid; // index in transaction table
     701      sc_signal<bool>     r_xram_rsp_to_ixr_cmd_req;   // Valid request
     702      sc_signal<addr_t>   r_xram_rsp_to_ixr_cmd_nline; // cache line index
     703      sc_signal<data_t> * r_xram_rsp_to_ixr_cmd_data;  // cache line data
     704      sc_signal<size_t>   r_xram_rsp_to_ixr_cmd_trdid; // index in transaction table
    697705
    698706      ////////////////////////////////////////////////////
     
    700708      ////////////////////////////////////////////////////
    701709
    702       sc_signal<int>       r_ixr_cmd_fsm;
    703       sc_signal<size_t>    r_ixr_cmd_cpt;
     710      sc_signal<int>      r_ixr_cmd_fsm;
     711      sc_signal<size_t>   r_ixr_cmd_cpt;
    704712
    705713      ////////////////////////////////////////////////////
     
    707715      ////////////////////////////////////////////////////
    708716
    709       sc_signal<int>       r_tgt_rsp_fsm;
    710       sc_signal<size_t>    r_tgt_rsp_cpt;
     717      sc_signal<int>      r_tgt_rsp_fsm;
     718      sc_signal<size_t>   r_tgt_rsp_cpt;
    711719
    712720      ////////////////////////////////////////////////////
     
    714722      ////////////////////////////////////////////////////
    715723
    716       sc_signal<int>      r_init_cmd_fsm;
     724      sc_signal<int>      r_init_cmd_fsm;
    717725      sc_signal<size_t>   r_init_cmd_cpt;
    718726      sc_signal<bool>     r_init_cmd_inst;
     
    722730      ////////////////////////////////////////////////////
    723731
    724       sc_signal<int>            r_alloc_dir_fsm;
     732      sc_signal<int>      r_alloc_dir_fsm;
     733      sc_signal<unsigned> r_alloc_dir_reset_cpt;
    725734
    726735      ////////////////////////////////////////////////////
     
    728737      ////////////////////////////////////////////////////
    729738
    730       sc_signal<int>            r_alloc_trt_fsm;
     739      sc_signal<int>      r_alloc_trt_fsm;
    731740
    732741      ////////////////////////////////////////////////////
     
    734743      ////////////////////////////////////////////////////
    735744
    736       sc_signal<int>            r_alloc_upt_fsm;
     745      sc_signal<int>      r_alloc_upt_fsm;
    737746
    738747      ////////////////////////////////////////////////////
     
    740749      ////////////////////////////////////////////////////
    741750
    742       sc_signal<int>            r_alloc_heap_fsm;
    743 
     751      sc_signal<int>      r_alloc_heap_fsm;
     752      sc_signal<unsigned> r_alloc_heap_reset_cpt;
    744753    }; // end class VciMemCacheV4
    745754
     
    755764// End:
    756765
    757 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    758 
     766// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=2:softtabstop=2
     767
  • trunk/modules/vci_mem_cache_v4/caba/source/src/vci_mem_cache_v4.cpp

    r253 r273  
    11 /* -*- c++ -*-
    2  * File         : vci_mem_cache_v4.cpp
    3  * Date         : 30/10/2008
    4  * Copyright    : UPMC / LIP6
    5  * Authors      : Alain Greiner / Eric Guthmuller
     2 * File       : vci_mem_cache_v4.cpp
     3 * Date       : 30/10/2008
     4 * Copyright  : UPMC / LIP6
     5 * Authors    : Alain Greiner / Eric Guthmuller
    66 *
    77 * SOCLIB_LGPL_HEADER_BEGIN
     
    2626 *
    2727 * Maintainers: alain eric.guthmuller@polytechnique.edu
     28 *              cesar.fuguet-tortolero@lip6.fr
    2829 */
    2930
     
    3233//////   debug services   ///////////////////////////////////////////////////////
    3334// All debug messages are conditionned by two variables:
    34 // - compile time : DEBUG_MEMC_*** : defined below
    35 // - execution time : m_debug_***  : defined by constructor arguments
     35// - compile time   : DEBUG_MEMC_*** : defined below
     36// - execution time : m_debug_***    : defined by constructor arguments
    3637//    m_debug_* = (m_debug_ok) and (m_cpt_cycle > m_debug_start_cycle)
    3738/////////////////////////////////////////////////////////////////////////////////
    3839
    39 #define DEBUG_MEMC_GLOBAL       0       // synthetic trace of all FSMs
    40 #define DEBUG_MEMC_READ         1       // detailed trace of READ FSM
    41 #define DEBUG_MEMC_WRITE        1       // detailed trace of WRITE FSM 
    42 #define DEBUG_MEMC_SC           1       // detailed trace of SC FSM     
    43 #define DEBUG_MEMC_IXR_CMD      1       // detailed trace of IXR_RSP FSM
    44 #define DEBUG_MEMC_IXR_RSP      1       // detailed trace of IXR_RSP FSM
    45 #define DEBUG_MEMC_XRAM_RSP     1       // detailed trace of XRAM_RSP FSM       
    46 #define DEBUG_MEMC_INIT_CMD     1       // detailed trace of INIT_CMD FSM       
    47 #define DEBUG_MEMC_INIT_RSP     1       // detailed trace of INIT_RSP FSM       
    48 #define DEBUG_MEMC_TGT_CMD      1       // detailed trace of TGT_CMD FSM       
    49 #define DEBUG_MEMC_TGT_RSP      1       // detailed trace of TGT_RSP FSM       
    50 #define DEBUG_MEMC_CLEANUP      1       // detailed trace of CLEANUP FSM       
    51 
    52 #define RANDOMIZE_SC            1
     40#define DEBUG_MEMC_GLOBAL   0 // synthetic trace of all FSMs
     41#define DEBUG_MEMC_READ     1 // detailed trace of READ FSM
     42#define DEBUG_MEMC_WRITE    1 // detailed trace of WRITE FSM
     43#define DEBUG_MEMC_SC       1 // detailed trace of SC FSM
     44#define DEBUG_MEMC_IXR_CMD  1 // detailed trace of IXR_RSP FSM
     45#define DEBUG_MEMC_IXR_RSP  1 // detailed trace of IXR_RSP FSM
     46#define DEBUG_MEMC_XRAM_RSP 1 // detailed trace of XRAM_RSP FSM
     47#define DEBUG_MEMC_INIT_CMD 1 // detailed trace of INIT_CMD FSM
     48#define DEBUG_MEMC_INIT_RSP 1 // detailed trace of INIT_RSP FSM
     49#define DEBUG_MEMC_TGT_CMD  1 // detailed trace of TGT_CMD FSM
     50#define DEBUG_MEMC_TGT_RSP  1 // detailed trace of TGT_RSP FSM
     51#define DEBUG_MEMC_CLEANUP  1 // detailed trace of CLEANUP FSM
     52
     53#define RANDOMIZE_SC        1
    5354
    5455namespace soclib { namespace caba {
     
    5859    "TGT_CMD_READ",
    5960    "TGT_CMD_WRITE",
    60     "TGT_CMD_ATOMIC",
     61    "TGT_CMD_ATOMIC"
    6162  };
    6263  const char *tgt_rsp_fsm_str[] = {
     
    7273    "TGT_RSP_XRAM",
    7374    "TGT_RSP_INIT",
    74     "TGT_RSP_CLEANUP",
     75    "TGT_RSP_CLEANUP"
    7576  };
    7677  const char *init_cmd_fsm_str[] = {
     
    8889    "INIT_CMD_SC_UPDT_INDEX",
    8990    "INIT_CMD_SC_UPDT_DATA",
    90     "INIT_CMD_SC_UPDT_DATA_HIGH",
     91    "INIT_CMD_SC_UPDT_DATA_HIGH"
    9192  };
    9293  const char *init_rsp_fsm_str[] = {
     
    9495    "INIT_RSP_UPT_LOCK",
    9596    "INIT_RSP_UPT_CLEAR",
    96     "INIT_RSP_END",
     97    "INIT_RSP_END"
    9798  };
    9899  const char *read_fsm_str[] = {
    99100    "READ_IDLE",
     101    "READ_DIR_REQ",
    100102    "READ_DIR_LOCK",
    101103    "READ_DIR_HIT",
     104    "READ_HEAP_REQ",
    102105    "READ_HEAP_LOCK",
    103106    "READ_HEAP_WRITE",
     
    107110    "READ_TRT_LOCK",
    108111    "READ_TRT_SET",
    109     "READ_TRT_REQ",
     112    "READ_TRT_REQ"
    110113  };
    111114  const char *write_fsm_str[] = {
    112115    "WRITE_IDLE",
    113116    "WRITE_NEXT",
     117    "WRITE_DIR_REQ",
    114118    "WRITE_DIR_LOCK",
    115119    "WRITE_DIR_READ",
     
    130134    "WRITE_BC_CC_SEND",
    131135    "WRITE_BC_XRAM_REQ",
    132     "WRITE_WAIT",
     136    "WRITE_WAIT"
    133137  };
    134138  const char *ixr_rsp_fsm_str[] = {
     
    136140    "IXR_RSP_ACK",
    137141    "IXR_RSP_TRT_ERASE",
    138     "IXR_RSP_TRT_READ",
     142    "IXR_RSP_TRT_READ"
    139143  };
    140144  const char *xram_rsp_fsm_str[] = {
     
    149153    "XRAM_RSP_INVAL",
    150154    "XRAM_RSP_WRITE_DIRTY",
     155    "XRAM_RSP_HEAP_REQ",
    151156    "XRAM_RSP_HEAP_ERASE",
    152157    "XRAM_RSP_HEAP_LAST",
    153158    "XRAM_RSP_ERROR_ERASE",
    154     "XRAM_RSP_ERROR_RSP",
     159    "XRAM_RSP_ERROR_RSP"
    155160  };
    156161  const char *ixr_cmd_fsm_str[] = {
     
    162167    "IXR_CMD_WRITE_NLINE",
    163168    "IXR_CMD_SC_NLINE",
    164     "IXR_CMD_XRAM_DATA",
     169    "IXR_CMD_XRAM_DATA"
    165170  };
    166171  const char *sc_fsm_str[] = {
    167172    "SC_IDLE",
     173    "SC_DIR_REQ",
    168174    "SC_DIR_LOCK",
    169175    "SC_DIR_HIT_READ",
     
    183189    "SC_MISS_TRT_SET",
    184190    "SC_MISS_XRAM_REQ",
    185     "SC_WAIT",
     191    "SC_WAIT"
    186192  };
    187193  const char *cleanup_fsm_str[] = {
    188194    "CLEANUP_IDLE",
     195    "CLEANUP_DIR_REQ",
    189196    "CLEANUP_DIR_LOCK",
    190197    "CLEANUP_DIR_WRITE",
     198    "CLEANUP_HEAP_REQ",
    191199    "CLEANUP_HEAP_LOCK",
    192200    "CLEANUP_HEAP_SEARCH",
     
    196204    "CLEANUP_UPT_WRITE",
    197205    "CLEANUP_WRITE_RSP",
    198     "CLEANUP_RSP",
     206    "CLEANUP_RSP"
    199207  };
    200208  const char *alloc_dir_fsm_str[] = {
     209    "ALLOC_DIR_RESET",
    201210    "ALLOC_DIR_READ",
    202211    "ALLOC_DIR_WRITE",
    203212    "ALLOC_DIR_SC",
    204213    "ALLOC_DIR_CLEANUP",
    205     "ALLOC_DIR_XRAM_RSP",
     214    "ALLOC_DIR_XRAM_RSP"
    206215  };
    207216  const char *alloc_trt_fsm_str[] = {
     
    210219    "ALLOC_TRT_SC",
    211220    "ALLOC_TRT_XRAM_RSP",
    212     "ALLOC_TRT_IXR_RSP",
     221    "ALLOC_TRT_IXR_RSP"
    213222  };
    214223  const char *alloc_upt_fsm_str[] = {
     
    217226    "ALLOC_UPT_INIT_RSP",
    218227    "ALLOC_UPT_CLEANUP",
     228    "ALLOC_UPT_SC"
    219229  };
    220230  const char *alloc_heap_fsm_str[] = {
     231    "ALLOC_HEAP_RESET",
    221232    "ALLOC_HEAP_READ",
    222233    "ALLOC_HEAP_WRITE",
    223234    "ALLOC_HEAP_SC",
    224235    "ALLOC_HEAP_CLEANUP",
    225     "ALLOC_HEAP_XRAM_RSP",
     236    "ALLOC_HEAP_XRAM_RSP"
    226237  };
    227238
     
    231242
    232243  ////////////////////////////////
    233   //    Constructor
     244  //  Constructor
    234245  ////////////////////////////////
    235246
    236   tmpl(/**/)::VciMemCacheV4( 
     247  tmpl(/**/)::VciMemCacheV4(
    237248      sc_module_name name,
    238249      const soclib::common::MappingTable &mtp,
     
    243254      const soclib::common::IntTab &vci_tgt_index,
    244255      const soclib::common::IntTab &vci_tgt_index_cleanup,
    245       size_t nways,                                         // number of ways per set
    246       size_t nsets,                                         // number of cache sets
    247       size_t nwords,                                        // number of words in cache line
    248       size_t heap_size,                                     // number of heap entries
    249       size_t transaction_tab_lines,                         // number of TRT entries
    250       size_t update_tab_lines,                              // number of UPT entries
     256      size_t nways,                 // number of ways per set
     257      size_t nsets,                 // number of cache sets
     258      size_t nwords,                // number of words in cache line
     259      size_t heap_size,             // number of heap entries
     260      size_t transaction_tab_lines, // number of TRT entries
     261      size_t update_tab_lines,      // number of UPT entries
    251262      size_t debug_start_cycle,
    252263      bool   debug_ok)
     
    287298#undef L2
    288299
    289     //  FIFOs 
     300    //  FIFOs
    290301
    291302    m_cmd_read_addr_fifo("m_cmd_read_addr_fifo", 4),
     
    311322
    312323    r_tgt_cmd_fsm("r_tgt_cmd_fsm"),
    313    
    314     m_nseg(0), 
    315     m_ncseg(0), 
     324
     325    m_nseg(0),
     326    m_ncseg(0),
    316327
    317328    r_read_fsm("r_read_fsm"),
     
    352363
    353364    r_alloc_dir_fsm("r_alloc_dir_fsm"),
     365    r_alloc_dir_reset_cpt("r_alloc_dir_reset_cpt"),
    354366    r_alloc_trt_fsm("r_alloc_trt_fsm"),
    355367    r_alloc_upt_fsm("r_alloc_upt_fsm"),
    356     r_alloc_heap_fsm("r_alloc_heap_fsm")
     368    r_alloc_heap_fsm("r_alloc_heap_fsm"),
     369    r_alloc_heap_reset_cpt("r_alloc_heap_reset_cpt")
    357370    {
    358371      assert(IS_POW_OF_2(nsets));
     
    370383      m_broadcast_address = 0x3 | (0x7C1F << (vci_param::N-20));
    371384
    372       // Get the segments associated to the MemCache 
     385      // Get the segments associated to the MemCache
    373386      std::list<soclib::common::Segment>::iterator seg;
    374387      size_t i;
     
    384397
    385398      i = 0;
    386       for ( seg = m_seglist.begin() ; seg != m_seglist.end() ; seg++ ) { 
     399      for ( seg = m_seglist.begin() ; seg != m_seglist.end() ; seg++ ) {
    387400        m_seg[i] = &(*seg);
    388401        i++;
     
    392405
    393406      i = 0;
    394       for ( seg = m_cseglist.begin() ; seg != m_cseglist.end() ; seg++ ) { 
     407      for ( seg = m_cseglist.begin() ; seg != m_cseglist.end() ; seg++ ) {
    395408          m_cseg[i] = &(*seg);
    396409          i++;
     
    407420          for ( size_t k=0; k<nwords; k++){
    408421            m_cache_data[i][j][k]=0;
    409           }     
     422          }
    410423        }
    411424      }
    412425
    413426      // Allocation for IXR_RSP FSM
    414       r_ixr_rsp_to_xram_rsp_rok     = new sc_signal<bool>[m_transaction_tab_lines];
     427      r_ixr_rsp_to_xram_rsp_rok   = new sc_signal<bool>[m_transaction_tab_lines];
    415428
    416429      // Allocation for XRAM_RSP FSM
    417       r_xram_rsp_victim_data        = new sc_signal<data_t>[nwords];
    418       r_xram_rsp_to_tgt_rsp_data    = new sc_signal<data_t>[nwords];
    419       r_xram_rsp_to_ixr_cmd_data    = new sc_signal<data_t>[nwords];
     430      r_xram_rsp_victim_data      = new sc_signal<data_t>[nwords];
     431      r_xram_rsp_to_tgt_rsp_data  = new sc_signal<data_t>[nwords];
     432      r_xram_rsp_to_ixr_cmd_data  = new sc_signal<data_t>[nwords];
    420433
    421434      // Allocation for READ FSM
    422       r_read_data                               = new sc_signal<data_t>[nwords];
    423       r_read_to_tgt_rsp_data            = new sc_signal<data_t>[nwords];
     435      r_read_data                 = new sc_signal<data_t>[nwords];
     436      r_read_to_tgt_rsp_data      = new sc_signal<data_t>[nwords];
    424437
    425438      // Allocation for WRITE FSM
    426       r_write_data                              = new sc_signal<data_t>[nwords];
    427       r_write_be                                = new sc_signal<be_t>[nwords];
    428       r_write_to_init_cmd_data          = new sc_signal<data_t>[nwords];
    429       r_write_to_init_cmd_be            = new sc_signal<be_t>[nwords];
    430       r_write_to_ixr_cmd_data       = new sc_signal<data_t>[nwords];
     439      r_write_data                = new sc_signal<data_t>[nwords];
     440      r_write_be                  = new sc_signal<be_t>[nwords];
     441      r_write_to_init_cmd_data    = new sc_signal<data_t>[nwords];
     442      r_write_to_init_cmd_be      = new sc_signal<be_t>[nwords];
     443      r_write_to_ixr_cmd_data     = new sc_signal<data_t>[nwords];
    431444
    432445      // Allocation for SC FSM
    433       r_sc_to_ixr_cmd_data              = new sc_signal<data_t>[nwords];
    434       r_sc_rdata                    = new sc_signal<data_t>[2];
     446      r_sc_to_ixr_cmd_data        = new sc_signal<data_t>[nwords];
     447      r_sc_rdata                  = new sc_signal<data_t>[2];
    435448
    436449
     
    471484    {
    472485        std::cout << " MEMC Write Monitor : " << buf << " Address = " << std::hex << addr
    473                   << " / Data = " << data << std::endl; 
     486                  << " / Data = " << data << std::endl;
    474487    }
    475488}
     
    480493{
    481494    DirectoryEntry entry = m_cache_directory.read_neutral(addr);
    482     if ( (entry.count != m_debug_previous_count) or 
     495    if ( (entry.count != m_debug_previous_count) or
    483496         (entry.valid != m_debug_previous_hit) )
    484497    {
     
    498511{
    499512    std::cout << "MEMC " << name() << std::endl;
    500     std::cout << "  "  << tgt_cmd_fsm_str[r_tgt_cmd_fsm] 
    501               << " | " << tgt_rsp_fsm_str[r_tgt_rsp_fsm] 
     513    std::cout << "  "  << tgt_cmd_fsm_str[r_tgt_cmd_fsm]
     514              << " | " << tgt_rsp_fsm_str[r_tgt_rsp_fsm]
    502515              << " | " << read_fsm_str[r_read_fsm]
    503               << " | " << write_fsm_str[r_write_fsm] 
    504               << " | " << sc_fsm_str[r_sc_fsm] 
     516              << " | " << write_fsm_str[r_write_fsm]
     517              << " | " << sc_fsm_str[r_sc_fsm]
    505518              << " | " << cleanup_fsm_str[r_cleanup_fsm] << std::endl;
    506519    std::cout << "  "  << init_cmd_fsm_str[r_init_cmd_fsm]
    507               << " | " << init_rsp_fsm_str[r_init_rsp_fsm] 
    508               << " | " << ixr_cmd_fsm_str[r_ixr_cmd_fsm] 
     520              << " | " << init_rsp_fsm_str[r_init_rsp_fsm]
     521              << " | " << ixr_cmd_fsm_str[r_ixr_cmd_fsm]
    509522              << " | " << ixr_rsp_fsm_str[r_ixr_rsp_fsm]
    510523              << " | " << xram_rsp_fsm_str[r_xram_rsp_fsm] << std::endl;
     
    515528/////////////////////////////////////////
    516529{
    517     std::cout << "----------------------------------" << std::dec << std::endl;
    518     std::cout << "MEM_CACHE " << m_srcid_ini << " / Time = " << m_cpt_cycles << std::endl
    519               << "- READ RATE            = " << (double)m_cpt_read/m_cpt_cycles << std::endl
    520               << "- READ TOTAL           = " << m_cpt_read << std::endl
    521               << "- READ MISS RATE       = " << (double)m_cpt_read_miss/m_cpt_read << std::endl
    522               << "- WRITE RATE           = " << (double)m_cpt_write/m_cpt_cycles << std::endl
    523               << "- WRITE TOTAL          = " << m_cpt_write << std::endl
    524               << "- WRITE MISS RATE      = " << (double)m_cpt_write_miss/m_cpt_write << std::endl
    525               << "- WRITE BURST LENGTH   = " << (double)m_cpt_write_cells/m_cpt_write << std::endl
    526               << "- WRITE BURST TOTAL    = " << m_cpt_write_cells << std::endl
    527               << "- REQUESTS TRT FULL    = " << m_cpt_trt_full << std::endl
    528               << "- READ TRT BLOKED HIT  = " << m_cpt_trt_rb << std::endl
    529               << "- UPDATE RATE          = " << (double)m_cpt_update/m_cpt_cycles << std::endl
    530               << "- UPDATE ARITY         = " << (double)m_cpt_update_mult/m_cpt_update << std::endl
    531               << "- INVAL MULTICAST RATE = " << (double)(m_cpt_inval-m_cpt_inval_brdcast)/m_cpt_cycles << std::endl
    532               << "- INVAL MULTICAST ARITY= " << (double)m_cpt_inval_mult/(m_cpt_inval-m_cpt_inval_brdcast) << std::endl
    533               << "- INVAL BROADCAST RATE = " << (double)m_cpt_inval_brdcast/m_cpt_cycles << std::endl
    534               << "- SAVE DIRTY RATE      = " << (double)m_cpt_write_dirty/m_cpt_cycles << std::endl
    535               << "- CLEANUP RATE         = " << (double)m_cpt_cleanup/m_cpt_cycles << std::endl
    536               << "- LL RATE              = " << (double)m_cpt_ll/m_cpt_cycles << std::endl
    537               << "- SC RATE              = " << (double)m_cpt_sc/m_cpt_cycles << std::endl;
     530  std::cout << "----------------------------------" << std::dec << std::endl;
     531  std::cout
     532    << "MEM_CACHE " << m_srcid_ini << " / Time = " << m_cpt_cycles << std::endl
     533    << "- READ RATE            = " << (double) m_cpt_read/m_cpt_cycles << std::endl
     534    << "- READ TOTAL           = " << m_cpt_read << std::endl
     535    << "- READ MISS RATE       = " << (double) m_cpt_read_miss/m_cpt_read << std::endl
     536    << "- WRITE RATE           = " << (double) m_cpt_write/m_cpt_cycles << std::endl
     537    << "- WRITE TOTAL          = " << m_cpt_write << std::endl
     538    << "- WRITE MISS RATE      = " << (double) m_cpt_write_miss/m_cpt_write << std::endl
     539    << "- WRITE BURST LENGTH   = " << (double) m_cpt_write_cells/m_cpt_write << std::endl
     540    << "- WRITE BURST TOTAL    = " << m_cpt_write_cells << std::endl
     541    << "- REQUESTS TRT FULL    = " << m_cpt_trt_full << std::endl
     542    << "- READ TRT BLOKED HIT  = " << m_cpt_trt_rb << std::endl
     543    << "- UPDATE RATE          = " << (double) m_cpt_update/m_cpt_cycles << std::endl
     544    << "- UPDATE ARITY         = " << (double) m_cpt_update_mult/m_cpt_update << std::endl
     545    << "- INVAL MULTICAST RATE = " << (double) (m_cpt_inval-m_cpt_inval_brdcast)/m_cpt_cycles << std::endl
     546    << "- INVAL MULTICAST ARITY= " << (double) m_cpt_inval_mult/(m_cpt_inval-m_cpt_inval_brdcast) << std::endl
     547    << "- INVAL BROADCAST RATE = " << (double) m_cpt_inval_brdcast/m_cpt_cycles << std::endl
     548    << "- SAVE DIRTY RATE      = " << (double) m_cpt_write_dirty/m_cpt_cycles << std::endl
     549    << "- CLEANUP RATE         = " << (double) m_cpt_cleanup/m_cpt_cycles << std::endl
     550    << "- LL RATE              = " << (double) m_cpt_ll/m_cpt_cycles << std::endl
     551    << "- SC RATE              = " << (double) m_cpt_sc/m_cpt_cycles << std::endl;
    538552}
    539553
     
    570584//////////////////////////////////
    571585{
    572     using soclib::common::uint32_log2;
    573 
    574     //  RESET         
    575     if ( ! p_resetn.read() ) {
    576 
    577       //    Initializing FSMs
    578       r_tgt_cmd_fsm     = TGT_CMD_IDLE;
    579       r_tgt_rsp_fsm     = TGT_RSP_READ_IDLE;
    580       r_init_cmd_fsm    = INIT_CMD_INVAL_IDLE;
    581       r_init_rsp_fsm    = INIT_RSP_IDLE;
    582       r_read_fsm            = READ_IDLE;
    583       r_write_fsm           = WRITE_IDLE;
    584       r_sc_fsm          = SC_IDLE;
    585       r_cleanup_fsm     = CLEANUP_IDLE;
    586       r_alloc_dir_fsm   = ALLOC_DIR_READ;
    587       r_alloc_heap_fsm  = ALLOC_HEAP_READ;
    588       r_alloc_trt_fsm   = ALLOC_TRT_READ;
    589       r_alloc_upt_fsm   = ALLOC_UPT_WRITE;
    590       r_ixr_rsp_fsm     = IXR_RSP_IDLE;
    591       r_xram_rsp_fsm    = XRAM_RSP_IDLE;
    592       r_ixr_cmd_fsm     = IXR_CMD_READ_IDLE;
    593 
    594       m_debug_global         = false;
    595       m_debug_tgt_cmd_fsm    = false;
    596       m_debug_tgt_rsp_fsm    = false;
    597       m_debug_init_cmd_fsm   = false;
    598       m_debug_init_rsp_fsm   = false;
    599       m_debug_read_fsm       = false;
    600       m_debug_write_fsm      = false;
    601       m_debug_sc_fsm         = false;
    602       m_debug_cleanup_fsm    = false;
    603       m_debug_ixr_cmd_fsm    = false;
    604       m_debug_ixr_rsp_fsm    = false;
    605       m_debug_xram_rsp_fsm   = false;
    606       m_debug_previous_hit   = false;
    607       m_debug_previous_count = 0;
    608 
    609       //  Initializing Tables
    610       m_cache_directory.init();
    611       m_transaction_tab.init();
    612       m_heap.init();
    613 
    614       // initializing FIFOs and communication Buffers
    615 
    616       m_cmd_read_addr_fifo.init();
    617       m_cmd_read_length_fifo.init();
    618       m_cmd_read_srcid_fifo.init();
    619       m_cmd_read_trdid_fifo.init();
    620       m_cmd_read_pktid_fifo.init();
    621 
    622       m_cmd_write_addr_fifo.init();
    623       m_cmd_write_eop_fifo.init();
    624       m_cmd_write_srcid_fifo.init();
    625       m_cmd_write_trdid_fifo.init();
    626       m_cmd_write_pktid_fifo.init();
    627       m_cmd_write_data_fifo.init();
    628 
    629       m_cmd_sc_addr_fifo.init();
    630       m_cmd_sc_srcid_fifo.init();
    631       m_cmd_sc_trdid_fifo.init();
    632       m_cmd_sc_pktid_fifo.init();
    633       m_cmd_sc_wdata_fifo.init();
    634       m_cmd_sc_eop_fifo.init();
    635 
    636       r_read_to_tgt_rsp_req                = false;
    637       r_read_to_ixr_cmd_req                 = false;
    638 
    639       r_write_to_tgt_rsp_req            = false;
    640       r_write_to_ixr_cmd_req            = false;
    641       r_write_to_init_cmd_multi_req        = false;
    642       r_write_to_init_cmd_brdcast_req   = false;
    643       r_write_to_init_rsp_req           = false;
    644       m_write_to_init_cmd_inst_fifo.init();
    645       m_write_to_init_cmd_srcid_fifo.init();
     586  using soclib::common::uint32_log2;
     587
     588  // RESET
     589  if ( ! p_resetn.read() ) {
     590
     591    // Initializing FSMs
     592    r_tgt_cmd_fsm    = TGT_CMD_IDLE;
     593    r_tgt_rsp_fsm    = TGT_RSP_READ_IDLE;
     594    r_init_cmd_fsm   = INIT_CMD_INVAL_IDLE;
     595    r_init_rsp_fsm   = INIT_RSP_IDLE;
     596    r_read_fsm       = READ_IDLE;
     597    r_write_fsm      = WRITE_IDLE;
     598    r_sc_fsm         = SC_IDLE;
     599    r_cleanup_fsm    = CLEANUP_IDLE;
     600    r_alloc_dir_fsm  = ALLOC_DIR_RESET;
     601    r_alloc_heap_fsm = ALLOC_HEAP_RESET;
     602    r_alloc_trt_fsm  = ALLOC_TRT_READ;
     603    r_alloc_upt_fsm  = ALLOC_UPT_WRITE;
     604    r_ixr_rsp_fsm    = IXR_RSP_IDLE;
     605    r_xram_rsp_fsm   = XRAM_RSP_IDLE;
     606    r_ixr_cmd_fsm    = IXR_CMD_READ_IDLE;
     607
     608    m_debug_global         = false;
     609    m_debug_tgt_cmd_fsm    = false;
     610    m_debug_tgt_rsp_fsm    = false;
     611    m_debug_init_cmd_fsm   = false;
     612    m_debug_init_rsp_fsm   = false;
     613    m_debug_read_fsm       = false;
     614    m_debug_write_fsm      = false;
     615    m_debug_sc_fsm         = false;
     616    m_debug_cleanup_fsm    = false;
     617    m_debug_ixr_cmd_fsm    = false;
     618    m_debug_ixr_rsp_fsm    = false;
     619    m_debug_xram_rsp_fsm   = false;
     620    m_debug_previous_hit   = false;
     621    m_debug_previous_count = 0;
     622
     623    //  Initializing Tables
     624    m_transaction_tab.init();
     625    m_update_tab.init();
     626
     627    // initializing FIFOs and communication Buffers
     628
     629    m_cmd_read_addr_fifo.init();
     630    m_cmd_read_length_fifo.init();
     631    m_cmd_read_srcid_fifo.init();
     632    m_cmd_read_trdid_fifo.init();
     633    m_cmd_read_pktid_fifo.init();
     634
     635    m_cmd_write_addr_fifo.init();
     636    m_cmd_write_eop_fifo.init();
     637    m_cmd_write_srcid_fifo.init();
     638    m_cmd_write_trdid_fifo.init();
     639    m_cmd_write_pktid_fifo.init();
     640    m_cmd_write_data_fifo.init();
     641
     642    m_cmd_sc_addr_fifo.init();
     643    m_cmd_sc_srcid_fifo.init();
     644    m_cmd_sc_trdid_fifo.init();
     645    m_cmd_sc_pktid_fifo.init();
     646    m_cmd_sc_wdata_fifo.init();
     647    m_cmd_sc_eop_fifo.init();
     648
     649    r_read_to_tgt_rsp_req = false;
     650    r_read_to_ixr_cmd_req = false;
     651
     652    r_write_to_tgt_rsp_req          = false;
     653    r_write_to_ixr_cmd_req          = false;
     654    r_write_to_init_cmd_multi_req   = false;
     655    r_write_to_init_cmd_brdcast_req = false;
     656    r_write_to_init_rsp_req         = false;
     657
     658    m_write_to_init_cmd_inst_fifo.init();
     659    m_write_to_init_cmd_srcid_fifo.init();
    646660#if L1_MULTI_CACHE
    647       m_write_to_init_cmd_cache_id_fifo.init();
    648 #endif
    649 
    650       r_cleanup_to_tgt_rsp_req          = false;
    651 
    652       r_init_rsp_to_tgt_rsp_req         = false;
    653 
    654       r_sc_to_tgt_rsp_req                   = false;
    655       r_sc_cpt                          = 0;
    656       r_sc_lfsr                         = -1;
    657       r_sc_to_ixr_cmd_req                   = false;
    658       r_sc_to_init_cmd_multi_req            = false;
    659       r_sc_to_init_cmd_brdcast_req          = false;
    660       m_sc_to_init_cmd_inst_fifo.init();
    661       m_sc_to_init_cmd_srcid_fifo.init();
     661    m_write_to_init_cmd_cache_id_fifo.init();
     662#endif
     663
     664    r_cleanup_to_tgt_rsp_req     = false;
     665
     666    r_init_rsp_to_tgt_rsp_req    = false;
     667
     668    r_sc_to_tgt_rsp_req          = false;
     669    r_sc_cpt                     = 0;
     670    r_sc_lfsr                    = -1;
     671    r_sc_to_ixr_cmd_req          = false;
     672    r_sc_to_init_cmd_multi_req   = false;
     673    r_sc_to_init_cmd_brdcast_req = false;
     674
     675    m_sc_to_init_cmd_inst_fifo.init();
     676    m_sc_to_init_cmd_srcid_fifo.init();
    662677#if L1_MULTI_CACHE
    663       m_sc_to_init_cmd_cache_id_fifo.init();
    664 #endif
    665 
    666       for(size_t i=0; i<m_transaction_tab_lines ; i++){
    667         r_ixr_rsp_to_xram_rsp_rok[i] = false;
    668       }
    669 
    670       r_xram_rsp_to_tgt_rsp_req             = false;
    671       r_xram_rsp_to_init_cmd_multi_req      = false;
    672       r_xram_rsp_to_init_cmd_brdcast_req    = false;
    673       r_xram_rsp_to_ixr_cmd_req             = false;
    674       r_xram_rsp_trt_index                      = 0;
    675       m_xram_rsp_to_init_cmd_inst_fifo.init();
    676       m_xram_rsp_to_init_cmd_srcid_fifo.init();
     678    m_sc_to_init_cmd_cache_id_fifo.init();
     679#endif
     680
     681    for(size_t i=0; i<m_transaction_tab_lines ; i++){
     682      r_ixr_rsp_to_xram_rsp_rok[i] = false;
     683    }
     684
     685    r_xram_rsp_to_tgt_rsp_req          = false;
     686    r_xram_rsp_to_init_cmd_multi_req   = false;
     687    r_xram_rsp_to_init_cmd_brdcast_req = false;
     688    r_xram_rsp_to_ixr_cmd_req          = false;
     689    r_xram_rsp_trt_index               = 0;
     690
     691    m_xram_rsp_to_init_cmd_inst_fifo.init();
     692    m_xram_rsp_to_init_cmd_srcid_fifo.init();
    677693#if L1_MULTI_CACHE
    678       m_xram_rsp_to_init_cmd_cache_id_fifo.init();
    679 #endif
    680 
    681       r_ixr_cmd_cpt         = 0;
    682 
    683       r_copies_limit        = 3;
    684 
    685       // Activity counters
    686       m_cpt_cycles                  = 0;
    687       m_cpt_read                    = 0;
    688       m_cpt_read_miss       = 0;
    689       m_cpt_write                   = 0;
    690       m_cpt_write_miss      = 0;
    691       m_cpt_write_cells     = 0;
    692       m_cpt_write_dirty     = 0;
    693       m_cpt_update                  = 0;
    694       m_cpt_update_mult     = 0;
    695       m_cpt_inval_brdcast       = 0;
    696       m_cpt_inval                   = 0;
    697       m_cpt_inval_mult          = 0;
    698       m_cpt_cleanup                 = 0;
    699       m_cpt_ll                      = 0;
    700       m_cpt_sc                      = 0;
    701       m_cpt_trt_full        = 0;
    702       m_cpt_trt_rb          = 0;
    703 
    704       return;
    705     }
    706 
    707     bool    cmd_read_fifo_put = false;
    708     bool    cmd_read_fifo_get = false;
    709 
    710     bool    cmd_write_fifo_put = false;
    711     bool    cmd_write_fifo_get = false;
    712 
    713     bool    cmd_sc_fifo_put = false;
    714     bool    cmd_sc_fifo_get = false;
    715 
    716     bool    write_to_init_cmd_fifo_put      = false;
    717     bool    write_to_init_cmd_fifo_get      = false;
    718     bool    write_to_init_cmd_fifo_inst     = false;
    719     size_t  write_to_init_cmd_fifo_srcid    = 0;
     694    m_xram_rsp_to_init_cmd_cache_id_fifo.init();
     695#endif
     696
     697    r_ixr_cmd_cpt          = 0;
     698    r_alloc_dir_reset_cpt  = 0;
     699    r_alloc_heap_reset_cpt = 0;
     700
     701    r_copies_limit         = 3;
     702
     703    // Activity counters
     704    m_cpt_cycles        = 0;
     705    m_cpt_read          = 0;
     706    m_cpt_read_miss     = 0;
     707    m_cpt_write         = 0;
     708    m_cpt_write_miss    = 0;
     709    m_cpt_write_cells   = 0;
     710    m_cpt_write_dirty   = 0;
     711    m_cpt_update        = 0;
     712    m_cpt_update_mult   = 0;
     713    m_cpt_inval_brdcast = 0;
     714    m_cpt_inval         = 0;
     715    m_cpt_inval_mult    = 0;
     716    m_cpt_cleanup       = 0;
     717    m_cpt_ll            = 0;
     718    m_cpt_sc            = 0;
     719    m_cpt_trt_full      = 0;
     720    m_cpt_trt_rb        = 0;
     721
     722    return;
     723  }
     724
     725  bool    cmd_read_fifo_put = false;
     726  bool    cmd_read_fifo_get = false;
     727
     728  bool    cmd_write_fifo_put = false;
     729  bool    cmd_write_fifo_get = false;
     730
     731  bool    cmd_sc_fifo_put = false;
     732  bool    cmd_sc_fifo_get = false;
     733
     734  bool    write_to_init_cmd_fifo_put   = false;
     735  bool    write_to_init_cmd_fifo_get   = false;
     736  bool    write_to_init_cmd_fifo_inst  = false;
     737  size_t  write_to_init_cmd_fifo_srcid = 0;
    720738
    721739#if L1_MULTI_CACHE
    722     size_t  write_to_init_cmd_fifo_cache_id = 0;
    723 #endif
    724 
    725     bool    xram_rsp_to_init_cmd_fifo_put      = false;
    726     bool    xram_rsp_to_init_cmd_fifo_get      = false;
    727     bool    xram_rsp_to_init_cmd_fifo_inst     = false;
    728     size_t  xram_rsp_to_init_cmd_fifo_srcid    = 0;
     740  size_t  write_to_init_cmd_fifo_cache_id = 0;
     741#endif
     742
     743  bool    xram_rsp_to_init_cmd_fifo_put   = false;
     744  bool    xram_rsp_to_init_cmd_fifo_get   = false;
     745  bool    xram_rsp_to_init_cmd_fifo_inst  = false;
     746  size_t  xram_rsp_to_init_cmd_fifo_srcid = 0;
    729747
    730748#if L1_MULTI_CACHE
    731     size_t  xram_rsp_to_init_cmd_fifo_cache_id = 0;
    732 #endif
    733 
    734     bool    sc_to_init_cmd_fifo_put      = false;
    735     bool    sc_to_init_cmd_fifo_get      = false;
    736     bool    sc_to_init_cmd_fifo_inst     = false;
    737     size_t  sc_to_init_cmd_fifo_srcid    = 0;
     749  size_t  xram_rsp_to_init_cmd_fifo_cache_id = 0;
     750#endif
     751
     752  bool    sc_to_init_cmd_fifo_put   = false;
     753  bool    sc_to_init_cmd_fifo_get   = false;
     754  bool    sc_to_init_cmd_fifo_inst  = false;
     755  size_t  sc_to_init_cmd_fifo_srcid = 0;
    738756
    739757#if L1_MULTI_CACHE
    740     size_t  sc_to_init_cmd_fifo_cache_id = 0;
    741 #endif
    742 
    743 m_debug_global       = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    744 m_debug_tgt_cmd_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    745 m_debug_tgt_rsp_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    746 m_debug_init_cmd_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    747 m_debug_init_rsp_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    748 m_debug_read_fsm     = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    749 m_debug_write_fsm    = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    750 m_debug_sc_fsm       = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    751 m_debug_cleanup_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    752 m_debug_ixr_cmd_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    753 m_debug_ixr_rsp_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    754 m_debug_xram_rsp_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
    755 
    756 
    757 #if DEBUG_MEMC_GLOBAL   
    758 if( m_debug_global )
    759 {
    760     std::cout << "---------------------------------------------" << std::dec << std::endl;
    761     std::cout << "MEM_CACHE " << m_srcid_ini << " ; Time = " << m_cpt_cycles << std::endl
     758  size_t  sc_to_init_cmd_fifo_cache_id = 0;
     759#endif
     760
     761  m_debug_global       = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     762  m_debug_tgt_cmd_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     763  m_debug_tgt_rsp_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     764  m_debug_init_cmd_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     765  m_debug_init_rsp_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     766  m_debug_read_fsm     = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     767  m_debug_write_fsm    = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     768  m_debug_sc_fsm       = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     769  m_debug_cleanup_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     770  m_debug_ixr_cmd_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     771  m_debug_ixr_rsp_fsm  = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     772  m_debug_xram_rsp_fsm = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
     773
     774#if DEBUG_MEMC_GLOBAL
     775  if( m_debug_global )
     776  {
     777    std::cout
     778      << "---------------------------------------------" << std::dec << std::endl
     779      << "MEM_CACHE " << m_srcid_ini << " ; Time = " << m_cpt_cycles << std::endl
    762780      << " - TGT_CMD FSM    = " << tgt_cmd_fsm_str[r_tgt_cmd_fsm] << std::endl
    763781      << " - TGT_RSP FSM    = " << tgt_rsp_fsm_str[r_tgt_rsp_fsm] << std::endl
     
    775793      << " - ALLOC_UPT FSM  = " << alloc_upt_fsm_str[r_alloc_upt_fsm] << std::endl
    776794      << " - ALLOC_HEAP FSM = " << alloc_heap_fsm_str[r_alloc_heap_fsm] << std::endl;
    777 }
    778 #endif
    779 
    780     ////////////////////////////////////////////////////////////////////////////////////
    781     //          TGT_CMD FSM
    782     ////////////////////////////////////////////////////////////////////////////////////
    783     // The TGT_CMD_FSM controls the incoming VCI command pakets from the processors
    784     //
    785     // There is 3 types of accepted commands :
    786     // - READ    : a READ request has a length of 1 VCI cell. It can be a single word
    787     //             or an entire cache line, depending on the PLEN value.
    788     // - WRITE   : a WRITE request has a maximum length of 16 cells, and can only
    789     //             concern words in a same line.
    790     // - SC      : The SC request has a length of 2 cells or 4 cells.
    791     ////////////////////////////////////////////////////////////////////////////////////
    792 
    793     switch ( r_tgt_cmd_fsm.read() )
     795  }
     796#endif
     797
     798  ////////////////////////////////////////////////////////////////////////////////////
     799  //    TGT_CMD FSM
     800  ////////////////////////////////////////////////////////////////////////////////////
     801  // The TGT_CMD_FSM controls the incoming VCI command pakets from the processors
     802  //
     803  // There is 3 types of accepted commands :
     804  // - READ    : a READ request has a length of 1 VCI cell. It can be a single word
     805  //             or an entire cache line, depending on the PLEN value.
     806  // - WRITE   : a WRITE request has a maximum length of 16 cells, and can only
     807  //             concern words in a same line.
     808  // - SC      : The SC request has a length of 2 cells or 4 cells.
     809  ////////////////////////////////////////////////////////////////////////////////////
     810
     811  switch ( r_tgt_cmd_fsm.read() )
     812  {
     813    //////////////////
     814    case TGT_CMD_IDLE:
     815      if ( p_vci_tgt.cmdval )
     816      {
     817
     818#if DEBUG_MEMC_TGT_CMD
     819        if( m_debug_tgt_cmd_fsm )
     820        {
     821          std::cout
     822            << "  <MEMC " << name() << ".TGT_CMD_IDLE> Receive command from srcid "
     823            << std::dec << p_vci_tgt.srcid.read()
     824            << " / for address " << std::hex << p_vci_tgt.address.read() << std::endl;
     825        }
     826#endif
     827        // checking segmentation violation
     828        vci_addr_t  address = p_vci_tgt.address.read();
     829        uint32_t    plen    = p_vci_tgt.plen.read();
     830        bool found = false;
     831        for ( size_t seg_id = 0 ; seg_id < m_nseg ; seg_id++ )
     832        {
     833          if ( m_seg[seg_id]->contains(address) &&
     834              m_seg[seg_id]->contains(address + plen - vci_param::B) )
     835          {
     836            found = true;
     837          }
     838        }
     839        if ( not found )
     840        {
     841          std::cout << "VCI_MEM_CACHE ERROR " << name() << std::endl;
     842          std::cout
     843            << "Out of segment VCI address in TGT_CMD_IDLE state (address = "
     844            << std::hex << address << ", srcid = " << p_vci_tgt.srcid.read()
     845            << std::dec << ", cycle = " << m_cpt_cycles << ")" << std::endl;
     846          exit(0);
     847        }
     848
     849        if ( p_vci_tgt.cmd.read() == vci_param::CMD_READ )
     850        {
     851          r_tgt_cmd_fsm = TGT_CMD_READ;
     852        }
     853        else if ( p_vci_tgt.cmd.read() == vci_param::CMD_WRITE )
     854        {
     855          r_tgt_cmd_fsm = TGT_CMD_WRITE;
     856        }
     857        else if ( p_vci_tgt.cmd.read() == vci_param::CMD_STORE_COND )
     858        {
     859          r_tgt_cmd_fsm = TGT_CMD_ATOMIC;
     860        }
     861        else
     862        {
     863          std::cout << "VCI_MEM_CACHE ERROR " << name()
     864            << " TGT_CMD_IDLE state" << std::endl;
     865          std::cout << " illegal VCI command type" << std::endl;
     866          exit(0);
     867        }
     868      }
     869      break;
     870
     871    //////////////////
     872    case TGT_CMD_READ:
     873      if ((m_x[(vci_addr_t)p_vci_tgt.address.read()]+(p_vci_tgt.plen.read()>>2)) > 16)
     874      {
     875        std::cout
     876          << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state"
     877          << std::endl;
     878        std::cout
     879          << " illegal address/plen combination for VCI read command" << std::endl;
     880        exit(0);
     881      }
     882      if ( !p_vci_tgt.eop.read() )
     883      {
     884        std::cout
     885          << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state"
     886          << std::endl;
     887        std::cout
     888          << " read command packets must contain one single flit"
     889          << std::endl;
     890        exit(0);
     891      }
     892
     893      if ( p_vci_tgt.cmdval && m_cmd_read_addr_fifo.wok() )
     894      {
     895
     896#if DEBUG_MEMC_TGT_CMD
     897        if( m_debug_tgt_cmd_fsm )
     898        {
     899          std::cout << "  <MEMC " << name() << ".TGT_CMD_READ> Push into read_fifo:"
     900            << " address = " << std::hex << p_vci_tgt.address.read()
     901            << " srcid = " << std::dec << p_vci_tgt.srcid.read()
     902            << " trdid = " << p_vci_tgt.trdid.read()
     903            << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
     904        }
     905#endif
     906        cmd_read_fifo_put = true;
     907        m_cpt_read++;
     908        r_tgt_cmd_fsm = TGT_CMD_IDLE;
     909      }
     910      break;
     911
     912    ///////////////////
     913    case TGT_CMD_WRITE:
     914      if ( p_vci_tgt.cmdval && m_cmd_write_addr_fifo.wok() )
     915      {
     916
     917#if DEBUG_MEMC_TGT_CMD
     918        if( m_debug_tgt_cmd_fsm )
     919        {
     920          std::cout << "  <MEMC " << name() << ".TGT_CMD_WRITE> Push into write_fifo:"
     921            << " address = " << std::hex << p_vci_tgt.address.read()
     922            << " srcid = " << std::dec << p_vci_tgt.srcid.read()
     923            << " trdid = " << p_vci_tgt.trdid.read()
     924            << " wdata = " << std::hex << p_vci_tgt.wdata.read()
     925            << " be = " << p_vci_tgt.be.read()
     926            << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
     927        }
     928#endif
     929        cmd_write_fifo_put = true;
     930        if(  p_vci_tgt.eop )  r_tgt_cmd_fsm = TGT_CMD_IDLE;
     931      }
     932      break;
     933
     934    ////////////////////
     935    case TGT_CMD_ATOMIC:
     936      if ( (p_vci_tgt.plen.read() != 8) && (p_vci_tgt.plen.read() != 16) )
     937      {
     938        std::cout
     939          << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_ATOMIC state"
     940          << std::endl
     941          << "illegal format for sc command " << std::endl;
     942
     943        exit(0);
     944      }
     945
     946      if ( p_vci_tgt.cmdval && m_cmd_sc_addr_fifo.wok() )
     947      {
     948
     949#if DEBUG_MEMC_TGT_CMD
     950        if( m_debug_tgt_cmd_fsm )
     951        {
     952          std::cout << "  <MEMC " << name() << ".TGT_CMD_ATOMIC> Pushing command into cmd_sc_fifo:"
     953            << " address = " << std::hex << p_vci_tgt.address.read()
     954            << " srcid = " << std::dec << p_vci_tgt.srcid.read()
     955            << " trdid = " << p_vci_tgt.trdid.read()
     956            << " wdata = " << std::hex << p_vci_tgt.wdata.read()
     957            << " be = " << p_vci_tgt.be.read()
     958            << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
     959        }
     960#endif
     961        cmd_sc_fifo_put = true;
     962        if( p_vci_tgt.eop ) r_tgt_cmd_fsm = TGT_CMD_IDLE;
     963      }
     964      break;
     965  } // end switch tgt_cmd_fsm
     966
     967  /////////////////////////////////////////////////////////////////////////
     968  //    INIT_RSP FSM
     969  /////////////////////////////////////////////////////////////////////////
     970  // This FSM controls the response to the update or inval coherence
     971  // requests sent by the memory cache to the L1 caches and update the UPT.
     972  //
     973  // It can be update or inval requests initiated by the WRITE FSM,
     974  // or inval requests initiated by the XRAM_RSP FSM.
     975  // It can also be a direct request from the WRITE FSM.
     976  //
     977  // The FSM decrements the proper entry in UPT.
     978  // It sends a request to the TGT_RSP FSM to complete the pending
     979  // write transaction (acknowledge response to the writer processor),
     980  // and clear the UPT entry when all responses have been received.
     981  //
     982  // All those response packets are one word, compact
     983  // packets complying with the VCI advanced format.
     984  // The index in the Table is defined in the RTRDID field, and
     985  // the transaction type is defined in the UPT entry.
     986  /////////////////////////////////////////////////////////////////////
     987
     988  switch ( r_init_rsp_fsm.read() )
     989  {
     990    ///////////////////
     991    case INIT_RSP_IDLE:   // wait a response for a coherence transaction
     992      if ( p_vci_ini.rspval )
     993      {
     994
     995#if DEBUG_MEMC_INIT_RSP
     996        if( m_debug_init_rsp_fsm )
     997        {
     998          std::cout <<  "  <MEMC " << name() << ".INIT_RSP_IDLE> Response for UPT entry "
     999            << p_vci_ini.rtrdid.read() << std::endl;
     1000        }
     1001#endif
     1002        if ( p_vci_ini.rtrdid.read() >= m_update_tab.size() )
     1003        {
     1004          std::cout
     1005            << "VCI_MEM_CACHE ERROR " << name()
     1006            << " INIT_RSP_IDLE state" << std::endl
     1007            << "index too large for UPT: "
     1008            << " / rtrdid = " << std::dec << p_vci_ini.rtrdid.read()
     1009            << " / UPT size = " << std::dec << m_update_tab.size()
     1010            << std::endl;
     1011
     1012          exit(0);
     1013        }
     1014        if ( !p_vci_ini.reop.read() )
     1015        {
     1016          std::cout
     1017            << "VCI_MEM_CACHE ERROR " << name()
     1018            << " INIT_RSP_IDLE state" << std::endl
     1019            << "all coherence response packets must be one flit"
     1020            << std::endl;
     1021
     1022          exit(0);
     1023        }
     1024
     1025        r_init_rsp_upt_index = p_vci_ini.rtrdid.read();
     1026        r_init_rsp_fsm = INIT_RSP_UPT_LOCK;
     1027      }
     1028      else if( r_write_to_init_rsp_req.read() )
     1029      {
     1030        r_init_rsp_upt_index = r_write_to_init_rsp_upt_index.read();
     1031        r_write_to_init_rsp_req = false;
     1032        r_init_rsp_fsm = INIT_RSP_UPT_LOCK;
     1033      }
     1034      break;
     1035
     1036    ///////////////////////
     1037    case INIT_RSP_UPT_LOCK: // decrement the number of expected responses
     1038      if ( r_alloc_upt_fsm.read() == ALLOC_UPT_INIT_RSP )
     1039      {
     1040        size_t count = 0;
     1041        bool valid   = m_update_tab.decrement(r_init_rsp_upt_index.read(), count);
     1042
     1043#if DEBUG_MEMC_INIT_RSP
     1044        if( m_debug_init_rsp_fsm )
     1045        {
     1046          std::cout << "  <MEMC " << name() << ".INIT_RSP_UPT_LOCK> Decrement the responses counter for UPT:"
     1047            << " entry = " << r_init_rsp_upt_index.read()
     1048            << " / rsp_count = " << std::dec << count << std::endl;
     1049        }
     1050#endif
     1051        if ( not valid )
     1052        {
     1053          std::cout << "VCI_MEM_CACHE ERROR " << name()
     1054            << " INIT_RSP_UPT_LOCK state" << std::endl
     1055            << "unsuccessful access to decrement the UPT" << std::endl;
     1056
     1057          exit(0);
     1058        }
     1059
     1060        if ( count == 0 ) r_init_rsp_fsm = INIT_RSP_UPT_CLEAR;
     1061        else              r_init_rsp_fsm = INIT_RSP_IDLE;
     1062      }
     1063      break;
     1064
     1065      ////////////////////////
     1066    case INIT_RSP_UPT_CLEAR:  // clear the UPT entry
     1067      if ( r_alloc_upt_fsm.read() == ALLOC_UPT_INIT_RSP )
     1068      {
     1069        r_init_rsp_srcid = m_update_tab.srcid(r_init_rsp_upt_index.read());
     1070        r_init_rsp_trdid = m_update_tab.trdid(r_init_rsp_upt_index.read());
     1071        r_init_rsp_pktid = m_update_tab.pktid(r_init_rsp_upt_index.read());
     1072        r_init_rsp_nline = m_update_tab.nline(r_init_rsp_upt_index.read());
     1073        bool need_rsp    = m_update_tab.need_rsp(r_init_rsp_upt_index.read());
     1074
     1075        if ( need_rsp ) r_init_rsp_fsm = INIT_RSP_END;
     1076        else            r_init_rsp_fsm = INIT_RSP_IDLE;
     1077
     1078        m_update_tab.clear(r_init_rsp_upt_index.read());
     1079
     1080#if DEBUG_MEMC_INIT_RSP
     1081        if ( m_debug_init_rsp_fsm )
     1082        {
     1083          std::cout <<  "  <MEMC " << name() << ".INIT_RSP_UPT_CLEAR> Clear UPT entry "
     1084            << r_init_rsp_upt_index.read() <<  std::endl;
     1085        }
     1086#endif
     1087      }
     1088      break;
     1089
     1090    //////////////////
     1091    case INIT_RSP_END:  // Post a request to TGT_RSP FSM
     1092      if ( !r_init_rsp_to_tgt_rsp_req )
     1093      {
     1094        r_init_rsp_to_tgt_rsp_req   = true;
     1095        r_init_rsp_to_tgt_rsp_srcid = r_init_rsp_srcid.read();
     1096        r_init_rsp_to_tgt_rsp_trdid = r_init_rsp_trdid.read();
     1097        r_init_rsp_to_tgt_rsp_pktid = r_init_rsp_pktid.read();
     1098        r_init_rsp_fsm = INIT_RSP_IDLE;
     1099
     1100#if DEBUG_MEMC_INIT_RSP
     1101        if ( m_debug_init_rsp_fsm )
     1102        {
     1103          std::cout
     1104            << "  <MEMC " << name()
     1105            << ".INIT_RSP_END> Request TGT_RSP FSM to send a response to srcid "
     1106            << r_init_rsp_srcid.read()
     1107            << std::endl;
     1108        }
     1109#endif
     1110      }
     1111      break;
     1112  } // end switch r_init_rsp_fsm
     1113
     1114  ////////////////////////////////////////////////////////////////////////////////////
     1115  //    READ FSM
     1116  ////////////////////////////////////////////////////////////////////////////////////
     1117  // The READ FSM controls the VCI read requests.
     1118  // It takes the lock protecting the cache directory to check the cache line status:
     1119  // - In case of HIT
     1120  //   The fsm copies the data (one line, or one single word)
     1121  //   in the r_read_to_tgt_rsp buffer. It waits if this buffer is not empty.
     1122  //   The requesting initiator is registered in the cache directory.
     1123  //   If the number of copy is larger than 1, the new copy is registered
     1124  //   in the HEAP.
     1125  //   If the number of copy is larger than the threshold, the HEAP is cleared,
     1126  //   and the corresponding line switches to the counter mode.
     1127  // - In case of MISS
     1128  //   The READ fsm takes the lock protecting the transaction tab.
     1129  //   If a read transaction to the XRAM for this line already exists,
     1130  //   or if the transaction tab is full, the fsm is stalled.
     1131  //   If a TRT entry is free, the READ request is registered in TRT,
     1132  //   it is consumed in the request FIFO, and transmited to the IXR_CMD FSM.
     1133  //   The READ FSM returns in the IDLE state as the read transaction will be
     1134  //   completed when the missing line will be received.
     1135  ////////////////////////////////////////////////////////////////////////////////////
     1136
     1137  switch ( r_read_fsm.read() )
     1138  {
     1139    ///////////////
     1140    case READ_IDLE:
     1141    // waiting a read request
    7941142    {
    795         //////////////////
    796         case TGT_CMD_IDLE:
    797         {
    798             if ( p_vci_tgt.cmdval )
    799             {
    800 
    801 #if DEBUG_MEMC_TGT_CMD
    802 if( m_debug_tgt_cmd_fsm )
    803 {
    804     std::cout << "  <MEMC " << name() << ".TGT_CMD_IDLE> Receive command from srcid " << std::dec << p_vci_tgt.srcid.read()
    805               << " / for address " << std::hex << p_vci_tgt.address.read() << std::endl;
    806 }
    807 #endif
    808                 // checking segmentation violation
    809                 vci_addr_t  address = p_vci_tgt.address.read();
    810                 uint32_t    plen    = p_vci_tgt.plen.read();
    811                 bool found = false;
    812                 for ( size_t seg_id = 0 ; seg_id < m_nseg ; seg_id++ )
    813                 {
    814                     if ( m_seg[seg_id]->contains(address) &&
    815                          m_seg[seg_id]->contains(address + plen - vci_param::B) )
    816                     {
    817                         found = true;
    818                     }
    819                 }
    820                 if ( not found )
    821                 {
    822                     std::cout << "VCI_MEM_CACHE ERROR " << name() << std::endl;
    823                     std::cout << "Out of segment VCI address in TGT_CMD_IDLE state (address = " << std::hex << address << ", srcid = " << p_vci_tgt.srcid.read() << std::dec << ", cycle = " << m_cpt_cycles << ")" << std::endl;
    824                     exit(0);
    825                 }
    826 
    827                 if ( p_vci_tgt.cmd.read() == vci_param::CMD_READ )
    828                 {
    829                     r_tgt_cmd_fsm = TGT_CMD_READ;
    830                 }
    831                 else if ( p_vci_tgt.cmd.read() == vci_param::CMD_WRITE )
    832                 { 
    833                     r_tgt_cmd_fsm = TGT_CMD_WRITE;
    834                 }
    835                 else if ( p_vci_tgt.cmd.read() == vci_param::CMD_STORE_COND )
    836                 {
    837                     r_tgt_cmd_fsm = TGT_CMD_ATOMIC;
    838                 }
    839                 else
    840                 {
    841                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    842                               << " TGT_CMD_IDLE state" << std::endl;
    843                     std::cout << " illegal VCI command type" << std::endl;
    844                     exit(0);
    845                 }
    846             }
    847             break;
    848         }
    849         //////////////////
    850         case TGT_CMD_READ:
    851         {
    852             if ((m_x[(vci_addr_t)p_vci_tgt.address.read()]+(p_vci_tgt.plen.read()>>2)) > 16)
    853             {
    854                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state" << std::endl;
    855                 std::cout << " illegal address/plen combination for VCI read command" << std::endl;
    856                 exit(0);
    857             }
    858             if ( !p_vci_tgt.eop.read() )
    859             {
    860                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state" << std::endl;
    861                 std::cout << " read command packets must contain one single flit" << std::endl;
    862                 exit(0);
    863             }
    864 
    865             if ( p_vci_tgt.cmdval && m_cmd_read_addr_fifo.wok() )
    866             {
    867            
    868 #if DEBUG_MEMC_TGT_CMD
    869 if( m_debug_tgt_cmd_fsm )
    870 {
    871     std::cout << "  <MEMC " << name() << ".TGT_CMD_READ> Push into read_fifo:"
    872               << " address = " << std::hex << p_vci_tgt.address.read()
    873               << " srcid = " << std::dec << p_vci_tgt.srcid.read()
    874               << " trdid = " << p_vci_tgt.trdid.read()
    875               << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
    876 }
    877 #endif
    878                 cmd_read_fifo_put = true;
    879                 m_cpt_read++;
    880                 r_tgt_cmd_fsm = TGT_CMD_IDLE;
    881             }
    882             break;
    883         }
    884         ///////////////////
    885         case TGT_CMD_WRITE:
    886         {
    887             if ( p_vci_tgt.cmdval && m_cmd_write_addr_fifo.wok() )
    888             {
    889            
    890 #if DEBUG_MEMC_TGT_CMD
    891 if( m_debug_tgt_cmd_fsm )
    892 {
    893     std::cout << "  <MEMC " << name() << ".TGT_CMD_WRITE> Push into write_fifo:"
    894               << " address = " << std::hex << p_vci_tgt.address.read()
    895               << " srcid = " << std::dec << p_vci_tgt.srcid.read()
    896               << " trdid = " << p_vci_tgt.trdid.read()
    897               << " wdata = " << std::hex << p_vci_tgt.wdata.read()
    898               << " be = " << p_vci_tgt.be.read()
    899               << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
    900 }
    901 #endif
    902                 cmd_write_fifo_put = true;
    903                 if(  p_vci_tgt.eop )  r_tgt_cmd_fsm = TGT_CMD_IDLE;
    904             }
    905             break;
    906         }
    907         ////////////////////
    908         case TGT_CMD_ATOMIC:
    909         {
    910             if ( (p_vci_tgt.plen.read() != 8) && (p_vci_tgt.plen.read() != 16) )
    911             {
    912                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_ATOMIC state" << std::endl;
    913                 std::cout << "illegal format for sc command " << std::endl;
    914                 exit(0);
    915             }
    916 
    917             if ( p_vci_tgt.cmdval && m_cmd_sc_addr_fifo.wok() )
    918             {
    919            
    920 #if DEBUG_MEMC_TGT_CMD
    921 if( m_debug_tgt_cmd_fsm )
    922 {
    923     std::cout << "  <MEMC " << name() << ".TGT_CMD_ATOMIC> Pushing command into cmd_sc_fifo:"
    924               << " address = " << std::hex << p_vci_tgt.address.read()
    925               << " srcid = " << std::dec << p_vci_tgt.srcid.read()
    926               << " trdid = " << p_vci_tgt.trdid.read()
    927               << " wdata = " << std::hex << p_vci_tgt.wdata.read()
    928               << " be = " << p_vci_tgt.be.read()
    929               << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
    930 }
    931 #endif
    932                 cmd_sc_fifo_put = true;
    933                 if( p_vci_tgt.eop ) r_tgt_cmd_fsm = TGT_CMD_IDLE;
    934             }
    935             break;
    936         }
    937     } // end switch tgt_cmd_fsm
    938 
    939     /////////////////////////////////////////////////////////////////////////
    940     //          INIT_RSP FSM
    941     /////////////////////////////////////////////////////////////////////////
    942     // This FSM controls the response to the update or inval coherence
    943     // requests sent by the memory cache to the L1 caches and update the UPT.
    944     //
    945     // It can be update or inval requests initiated by the WRITE FSM,
    946     // or inval requests initiated by the XRAM_RSP FSM. 
    947     // It can also be a direct request from the WRITE FSM.
    948     //
    949     // The FSM decrements the proper entry in UPT.
    950     // It sends a request to the TGT_RSP FSM to complete the pending
    951     // write transaction (acknowledge response to the writer processor),
    952     // and clear the UPT entry when all responses have been received. 
    953     //
    954     // All those response packets are one word, compact
    955     // packets complying with the VCI advanced format.
    956     // The index in the Table is defined in the RTRDID field, and
    957     // the transaction type is defined in the UPT entry.
    958     /////////////////////////////////////////////////////////////////////
    959 
    960     switch ( r_init_rsp_fsm.read() )
     1143      if (m_cmd_read_addr_fifo.rok())
     1144      {
     1145
     1146#if DEBUG_MEMC_READ
     1147        if( m_debug_read_fsm )
     1148        {
     1149          std::cout << "  <MEMC " << name() << ".READ_IDLE> Read request:"
     1150            << " srcid = " << std::dec << m_cmd_read_srcid_fifo.read()
     1151            << " / address = " << std::hex << m_cmd_read_addr_fifo.read()
     1152            << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
     1153        }
     1154#endif
     1155        r_read_fsm = READ_DIR_REQ;
     1156      }
     1157      break;
     1158    }
     1159
     1160    ///////////////////
     1161    case READ_DIR_REQ:
     1162    // Get the lock to the directory
    9611163    {
    962         ///////////////////
    963         case INIT_RSP_IDLE:   // wait a response for a coherence transaction
    964         {
    965             if ( p_vci_ini.rspval )
    966             {
    967 
    968 #if DEBUG_MEMC_INIT_RSP
    969 if( m_debug_init_rsp_fsm )
    970 {
    971     std::cout <<  "  <MEMC " << name() << ".INIT_RSP_IDLE> Response for UPT entry "
    972               << p_vci_ini.rtrdid.read() << std::endl;
    973 }
    974 #endif
    975                 if ( p_vci_ini.rtrdid.read() >= m_update_tab.size() )
    976                 {
    977                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    978                               << " INIT_RSP_IDLE state" << std::endl
    979                               << "index too large for UPT: "
    980                               << " / rtrdid = " << std::dec << p_vci_ini.rtrdid.read()
    981                               << " / UPT size = " << std::dec << m_update_tab.size() << std::endl;
    982                     exit(0);
    983                 }
    984                 if ( !p_vci_ini.reop.read() )
    985                 {
    986                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    987                               << " INIT_RSP_IDLE state" << std::endl;
    988                     std::cout << "all coherence response packets must be one flit" << std::endl;
    989                     exit(0);
    990                 }
    991 
    992                 r_init_rsp_upt_index = p_vci_ini.rtrdid.read();
    993                 r_init_rsp_fsm = INIT_RSP_UPT_LOCK;
    994             }
    995             else if( r_write_to_init_rsp_req.read() )
    996             {
    997                 r_init_rsp_upt_index = r_write_to_init_rsp_upt_index.read();
    998                 r_write_to_init_rsp_req = false;
    999                 r_init_rsp_fsm = INIT_RSP_UPT_LOCK;
    1000             }
    1001             break;
    1002         }
    1003         ///////////////////////
    1004         case INIT_RSP_UPT_LOCK: // decrement the number of expected responses
    1005         {
    1006             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_INIT_RSP )
    1007             {
    1008                 size_t count = 0;
    1009                 bool valid  = m_update_tab.decrement(r_init_rsp_upt_index.read(), count);
    1010 
    1011 #if DEBUG_MEMC_INIT_RSP
    1012 if( m_debug_init_rsp_fsm )
    1013 {
    1014     std::cout << "  <MEMC " << name() << ".INIT_RSP_UPT_LOCK> Decrement the responses counter for UPT:"
    1015               << " entry = " << r_init_rsp_upt_index.read()
    1016               << " / rsp_count = " << std::dec << count << std::endl;
    1017 }
    1018 #endif
    1019                 if ( not valid )
    1020                 {
    1021                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    1022                               << " INIT_RSP_UPT_LOCK state" << std::endl
    1023                               << "unsuccessful access to decrement the UPT" << std::endl;
    1024                     exit(0);
    1025                 }
    1026 
    1027                 if ( count == 0 ) r_init_rsp_fsm = INIT_RSP_UPT_CLEAR;
    1028                 else              r_init_rsp_fsm = INIT_RSP_IDLE;
    1029             }
    1030             break;
    1031         }
    1032         ////////////////////////
    1033         case INIT_RSP_UPT_CLEAR:        // clear the UPT entry
    1034         {
    1035             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_INIT_RSP )
    1036             {
    1037                 r_init_rsp_srcid = m_update_tab.srcid(r_init_rsp_upt_index.read());
    1038                 r_init_rsp_trdid = m_update_tab.trdid(r_init_rsp_upt_index.read());
    1039                 r_init_rsp_pktid = m_update_tab.pktid(r_init_rsp_upt_index.read());
    1040                 r_init_rsp_nline = m_update_tab.nline(r_init_rsp_upt_index.read());
    1041                 bool need_rsp    = m_update_tab.need_rsp(r_init_rsp_upt_index.read());
    1042 
    1043                 if ( need_rsp ) r_init_rsp_fsm = INIT_RSP_END;
    1044                 else            r_init_rsp_fsm = INIT_RSP_IDLE;
    1045 
    1046                 m_update_tab.clear(r_init_rsp_upt_index.read());
    1047 
    1048 #if DEBUG_MEMC_INIT_RSP
    1049 if ( m_debug_init_rsp_fsm )
    1050 {
    1051     std::cout <<  "  <MEMC " << name() << ".INIT_RSP_UPT_CLEAR> Clear UPT entry "
    1052               << r_init_rsp_upt_index.read() <<  std::endl;
    1053 }
    1054 #endif
    1055             }
    1056             break;
    1057         }
    1058         //////////////////
    1059         case INIT_RSP_END:      // Post a request to TGT_RSP FSM
    1060         {
    1061             if ( !r_init_rsp_to_tgt_rsp_req )
    1062             {
    1063                 r_init_rsp_to_tgt_rsp_req   = true;
    1064                 r_init_rsp_to_tgt_rsp_srcid = r_init_rsp_srcid.read();
    1065                 r_init_rsp_to_tgt_rsp_trdid = r_init_rsp_trdid.read();
    1066                 r_init_rsp_to_tgt_rsp_pktid = r_init_rsp_pktid.read();
    1067                 r_init_rsp_fsm = INIT_RSP_IDLE;
    1068 
    1069 #if DEBUG_MEMC_INIT_RSP
    1070 if ( m_debug_init_rsp_fsm )
    1071 {
    1072     std::cout <<  "  <MEMC " << name() << ".INIT_RSP_END> Request TGT_RSP FSM to send a response to srcid "
    1073               << r_init_rsp_srcid.read() <<  std::endl;
    1074 }
    1075 #endif
    1076             }
    1077             break;
    1078         }
    1079     } // end switch r_init_rsp_fsm
    1080 
    1081     ////////////////////////////////////////////////////////////////////////////////////
    1082     //          READ FSM
    1083     ////////////////////////////////////////////////////////////////////////////////////
    1084     // The READ FSM controls the VCI read requests.
    1085     // It takes the lock protecting the cache directory to check the cache line status:
    1086     // - In case of HIT
    1087     //   The fsm copies the data (one line, or one single word)
    1088     //   in the r_read_to_tgt_rsp buffer. It waits if this buffer is not empty.
    1089     //   The requesting initiator is registered in the cache directory.
    1090     //   If the number of copy is larger than 1, the new copy is registered
    1091     //   in the HEAP.
    1092     //   If the number of copy is larger than the threshold, the HEAP is cleared,
    1093     //   and the corresponding line switches to the counter mode.
    1094     // - In case of MISS
    1095     //   The READ fsm takes the lock protecting the transaction tab.
    1096     //   If a read transaction to the XRAM for this line already exists,
    1097     //   or if the transaction tab is full, the fsm is stalled.
    1098     //   If a TRT entry is free, the READ request is registered in TRT,
    1099     //   it is consumed in the request FIFO, and transmited to the IXR_CMD FSM.
    1100     //   The READ FSM returns in the IDLE state as the read transaction will be
    1101     //   completed when the missing line will be received.
    1102     ////////////////////////////////////////////////////////////////////////////////////
    1103 
    1104     switch ( r_read_fsm.read() )
     1164      if ( r_alloc_dir_fsm.read() == ALLOC_DIR_READ )
     1165      {
     1166        r_read_fsm = READ_DIR_LOCK;
     1167      }
     1168
     1169#if DEBUG_MEMC_READ
     1170      if( m_debug_read_fsm )
     1171      {
     1172        std::cout
     1173          << "  <MEMC " << name() << ".READ_DIR_REQ> Requesting DIR lock "
     1174          << std::endl;
     1175      }
     1176#endif
     1177      break;
     1178    }
     1179
     1180    ///////////////////
     1181    case READ_DIR_LOCK:
     1182    // check directory for hit / miss
    11051183    {
    1106         ///////////////
    1107         case READ_IDLE:         // waiting a read request
    1108         {
    1109             if (m_cmd_read_addr_fifo.rok())
    1110             {
     1184      if ( r_alloc_dir_fsm.read() == ALLOC_DIR_READ )
     1185      {
     1186        size_t way = 0;
     1187        DirectoryEntry entry =
     1188          m_cache_directory.read(m_cmd_read_addr_fifo.read(), way);
     1189
     1190        r_read_is_cnt     = entry.is_cnt;
     1191        r_read_dirty      = entry.dirty;
     1192        r_read_lock       = entry.lock;
     1193        r_read_tag        = entry.tag;
     1194        r_read_way        = way;
     1195        r_read_count      = entry.count;
     1196        r_read_copy       = entry.owner.srcid;
     1197
     1198#if L1_MULTI_CACHE
     1199        r_read_copy_cache = entry.owner.cache_id;
     1200#endif
     1201        r_read_copy_inst  = entry.owner.inst;
     1202        r_read_ptr        = entry.ptr; // pointer to the heap
     1203
     1204        bool cached_read = (m_cmd_read_trdid_fifo.read() & 0x1);
     1205        if(  entry.valid ) // hit
     1206        {
     1207          // test if we need to register a new copy in the heap
     1208          if ( entry.is_cnt || (entry.count == 0) || !cached_read )
     1209          {
     1210            r_read_fsm = READ_DIR_HIT;
     1211          }
     1212          else
     1213          {
     1214            r_read_fsm = READ_HEAP_REQ;
     1215          }
     1216        }
     1217        else      // miss
     1218        {
     1219          r_read_fsm = READ_TRT_LOCK;
     1220        }
    11111221
    11121222#if DEBUG_MEMC_READ
    1113 if( m_debug_read_fsm )
    1114 {
    1115     std::cout << "  <MEMC " << name() << ".READ_IDLE> Read request:"
    1116               << " srcid = " << std::dec << m_cmd_read_srcid_fifo.read()
    1117               << " / address = " << std::hex << m_cmd_read_addr_fifo.read()
    1118               << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
    1119 }
    1120 #endif
    1121                 r_read_fsm = READ_DIR_LOCK;
    1122             }
    1123             break;
    1124         }
    1125         ///////////////////
    1126         case READ_DIR_LOCK:     // check directory for hit / miss
    1127         {
    1128             if ( r_alloc_dir_fsm.read() == ALLOC_DIR_READ )
    1129             {
    1130                 size_t way = 0;
    1131                 DirectoryEntry entry = m_cache_directory.read(m_cmd_read_addr_fifo.read(), way);
    1132 
    1133                 r_read_is_cnt     = entry.is_cnt;
    1134                 r_read_dirty      = entry.dirty;
    1135                 r_read_lock           = entry.lock;
    1136                 r_read_tag            = entry.tag;
    1137                 r_read_way            = way;
    1138                 r_read_count      = entry.count;
    1139                 r_read_copy       = entry.owner.srcid;
    1140 
     1223        if( m_debug_read_fsm )
     1224        {
     1225          std::cout
     1226            << "  <MEMC " << name() << ".READ_DIR_LOCK> Accessing directory: "
     1227            << " address = " << std::hex << m_cmd_read_addr_fifo.read()
     1228            << " / hit = " << std::dec << entry.valid
     1229            << " / count = " <<std::dec << entry.count
     1230            << " / is_cnt = " << entry.is_cnt << std::endl;
     1231        }
     1232#endif
     1233      }
     1234      else
     1235      {
     1236        std::cout
     1237          << "VCI_MEM_CACHE ERROR " << name()
     1238          << " READ_DIR_LOCK state" << std::endl
     1239          << "Bad DIR allocation"   << std::endl;
     1240
     1241        exit(0);
     1242      }
     1243      break;
     1244    }
     1245
     1246    //////////////////
     1247    case READ_DIR_HIT:
     1248    {
     1249      //  read data in cache & update the directory
     1250      //  we enter this state in 3 cases:
     1251      //  - the read request is uncachable
     1252      //  - the cache line is in counter mode
     1253      //  - the cache line is valid but not replcated
     1254
     1255      if( r_alloc_dir_fsm.read() == ALLOC_DIR_READ )
     1256      {
     1257        // signals generation
     1258        bool inst_read    = (m_cmd_read_trdid_fifo.read() & 0x2);
     1259        bool cached_read  = (m_cmd_read_trdid_fifo.read() & 0x1);
     1260        bool is_cnt       = r_read_is_cnt.read();
     1261
     1262        // read data in the cache
     1263        size_t set        = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
     1264        size_t way        = r_read_way.read();
     1265        for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i];
     1266
     1267        // update the cache directory
     1268        DirectoryEntry entry;
     1269        entry.valid   = true;
     1270        entry.is_cnt  = is_cnt;
     1271        entry.dirty   = r_read_dirty.read();
     1272        entry.tag   = r_read_tag.read();
     1273        entry.lock    = r_read_lock.read();
     1274        entry.ptr     = r_read_ptr.read();
     1275        if (cached_read)  // Cached read => we must update the copies
     1276        {
     1277          if (!is_cnt) // Not counter mode
     1278          {
     1279            entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
    11411280#if L1_MULTI_CACHE
    1142                 r_read_copy_cache = entry.owner.cache_id;
    1143 #endif
    1144                 r_read_copy_inst  = entry.owner.inst;
    1145                 r_read_ptr        = entry.ptr;              // pointer to the heap
    1146 
    1147                 bool cached_read = (m_cmd_read_trdid_fifo.read() & 0x1);
    1148                 if(  entry.valid )      // hit
    1149                 {
    1150                     // test if we need to register a new copy in the heap
    1151                     if ( entry.is_cnt || (entry.count == 0) || !cached_read )
    1152                         r_read_fsm = READ_DIR_HIT;
    1153                     else
    1154                         r_read_fsm = READ_HEAP_LOCK;
    1155                 }
    1156                 else                    // miss
    1157                 {
    1158                     r_read_fsm = READ_TRT_LOCK;
    1159                 }
     1281            entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
     1282#endif
     1283            entry.owner.inst     = inst_read;
     1284            entry.count          = r_read_count.read() + 1;
     1285          }
     1286          else  // Counter mode
     1287          {
     1288            entry.owner.srcid    = 0;
     1289#if L1_MULTI_CACHE
     1290            entry.owner.cache_id = 0;
     1291#endif
     1292            entry.owner.inst     = false;
     1293            entry.count          = r_read_count.read() + 1;
     1294          }
     1295        }
     1296        else  // Uncached read
     1297        {
     1298          entry.owner.srcid     = r_read_copy.read();
     1299#if L1_MULTI_CACHE
     1300          entry.owner.cache_id  = r_read_copy_cache.read();
     1301#endif
     1302          entry.owner.inst      = r_read_copy_inst.read();
     1303          entry.count           = r_read_count.read();
     1304        }
    11601305
    11611306#if DEBUG_MEMC_READ
    1162 if( m_debug_read_fsm )
    1163 {
    1164     std::cout << "  <MEMC " << name() << ".READ_DIR_LOCK> Accessing directory: "
    1165               << " address = " << std::hex << m_cmd_read_addr_fifo.read()
    1166               << " / hit = " << std::dec << entry.valid
    1167               << " / count = " <<std::dec << entry.count
    1168               << " / is_cnt = " << entry.is_cnt << std::endl;
    1169 }
    1170 #endif
    1171             }
    1172             break;
    1173         }
    1174         //////////////////
    1175         case READ_DIR_HIT:          //  read data in cache & update the directory
    1176                                 //  we enter this state in 3 cases:
    1177                                 //  - the read request is uncachable
    1178                                 //  - the cache line is in counter mode
    1179                                 //  - the cache line is valid but not replcated
    1180         {
    1181             if( r_alloc_dir_fsm.read() == ALLOC_DIR_READ )
    1182             {
    1183                 // signals generation
    1184                 bool inst_read    = (m_cmd_read_trdid_fifo.read() & 0x2);
    1185                 bool cached_read  = (m_cmd_read_trdid_fifo.read() & 0x1);
    1186                 bool is_cnt       = r_read_is_cnt.read();
    1187 
    1188                 // read data in the cache
    1189                 size_t set        = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
    1190                 size_t way        = r_read_way.read();
    1191                 for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i];
    1192 
    1193                 // update the cache directory
    1194                 DirectoryEntry entry;
    1195                 entry.valid       = true;
    1196                 entry.is_cnt  = is_cnt;
    1197                 entry.dirty       = r_read_dirty.read();
    1198                 entry.tag         = r_read_tag.read();
    1199                 entry.lock        = r_read_lock.read();
    1200                 entry.ptr     = r_read_ptr.read();
    1201                 if (cached_read)  // Cached read => we must update the copies
    1202                 {
    1203                     if (!is_cnt) // Not counter mode
    1204                     {
    1205                         entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
     1307        if( m_debug_read_fsm )
     1308        {
     1309          std::cout
     1310            << "  <MEMC " << name() << ".READ_DIR_HIT> Update directory entry:"
     1311            << " set = " << std::dec << set
     1312            << " / way = " << way
     1313            << " / owner_id = " << entry.owner.srcid
     1314            << " / owner_ins = " << entry.owner.inst
     1315            << " / count = " << entry.count
     1316            << " / is_cnt = " << entry.is_cnt << std::endl;
     1317        }
     1318#endif
     1319
     1320        m_cache_directory.write(set, way, entry);
     1321        r_read_fsm    = READ_RSP;
     1322      }
     1323      break;
     1324    }
     1325
     1326    ////////////////////
     1327    case READ_HEAP_REQ:
     1328    // Get the lock to the HEAP directory
     1329    {
     1330      if( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
     1331      {
     1332        r_read_fsm = READ_HEAP_LOCK;
     1333      }
     1334
     1335#if DEBUG_MEMC_READ
     1336      if( m_debug_read_fsm )
     1337      {
     1338        std::cout
     1339          << "  <MEMC " << name() << ".READ_HEAP_REQ> Requesting HEAP lock "
     1340          << std::endl;
     1341      }
     1342#endif
     1343      break;
     1344    }
     1345
     1346    ////////////////////
     1347    case READ_HEAP_LOCK:
     1348    // read data in cache, update the directory
     1349    // and prepare the HEAP update
     1350    {
     1351      if( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
     1352      {
     1353        // enter counter mode when we reach the limit of copies or the heap is full
     1354        bool go_cnt = (r_read_count.read() >= r_copies_limit.read()) || m_heap.is_full();
     1355
     1356        // read data in the cache
     1357        size_t set = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
     1358        size_t way = r_read_way.read();
     1359        for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i];
     1360
     1361        // update the cache directory
     1362        DirectoryEntry entry;
     1363        entry.valid  = true;
     1364        entry.is_cnt = go_cnt;
     1365        entry.dirty  = r_read_dirty.read();
     1366        entry.tag    = r_read_tag.read();
     1367        entry.lock   = r_read_lock.read();
     1368        entry.count  = r_read_count.read() + 1;
     1369
     1370        if (not go_cnt)        // Not entering counter mode
     1371        {
     1372          entry.owner.srcid    = r_read_copy.read();
    12061373#if L1_MULTI_CACHE
    1207                         entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
    1208 #endif
    1209                         entry.owner.inst     = inst_read;
    1210                         entry.count          = r_read_count.read() + 1;
    1211                     }
    1212                     else  // Counter mode
    1213                     {
    1214                         entry.owner.srcid    = 0;
     1374          entry.owner.cache_id = r_read_copy_cache.read();
     1375#endif
     1376          entry.owner.inst     = r_read_copy_inst.read();
     1377          entry.ptr            = m_heap.next_free_ptr();   // set pointer on the heap
     1378        }
     1379        else                // Entering Counter mode
     1380        {
     1381          entry.owner.srcid    = 0;
    12151382#if L1_MULTI_CACHE
    1216                         entry.owner.cache_id = 0;
    1217 #endif
    1218                         entry.owner.inst     = false;
    1219                         entry.count          = r_read_count.read() + 1;
    1220                     }
    1221                 }
    1222                 else  // Uncached read
    1223                 {
    1224                     entry.owner.srcid     = r_read_copy.read();
     1383          entry.owner.cache_id = 0;
     1384#endif
     1385          entry.owner.inst     = false;
     1386          entry.ptr            = 0;
     1387        }
     1388
     1389        m_cache_directory.write(set, way, entry);
     1390
     1391        // prepare the heap update (add an entry, or clear the linked list)
     1392        if (not go_cnt)     // not switching to counter mode
     1393        {
     1394          // We test if the next free entry in the heap is the last
     1395          HeapEntry heap_entry = m_heap.next_free_entry();
     1396          r_read_next_ptr      = heap_entry.next;
     1397          r_read_last_free     = ( heap_entry.next == m_heap.next_free_ptr() );
     1398
     1399          r_read_fsm           = READ_HEAP_WRITE; // add an entry in the HEAP
     1400        }
     1401        else            // switching to counter mode
     1402        {
     1403          if ( r_read_count.read()>1 )            // heap must be cleared
     1404          {
     1405            HeapEntry next_entry = m_heap.read(r_read_ptr.read());
     1406            r_read_next_ptr      = m_heap.next_free_ptr();
     1407            m_heap.write_free_ptr(r_read_ptr.read());
     1408
     1409            if( next_entry.next == r_read_ptr.read() )  // last entry
     1410            {
     1411              r_read_fsm = READ_HEAP_LAST;    // erase the entry
     1412            }
     1413            else                                        // not the last entry
     1414            {
     1415              r_read_ptr = next_entry.next;
     1416              r_read_fsm = READ_HEAP_ERASE;   // erase the list
     1417            }
     1418          }
     1419          else  // the heap is not used / nothing to do
     1420          {
     1421            r_read_fsm = READ_RSP;
     1422          }
     1423        }
     1424
     1425#if DEBUG_MEMC_READ
     1426        if( m_debug_read_fsm )
     1427        {
     1428          std::cout << "  <MEMC " << name() << ".READ_HEAP_LOCK> Update directory:"
     1429            << " tag = " << std::hex << entry.tag
     1430            << " set = " << std::dec << set
     1431            << " way = " << way
     1432            << " count = " << entry.count
     1433            << " is_cnt = " << entry.is_cnt << std::endl;
     1434        }
     1435#endif
     1436      }
     1437      else
     1438      {
     1439        std::cout
     1440          << "VCI_MEM_CACHE ERROR " << name()
     1441          << " READ_HEAP_LOCK state" << std::endl
     1442          << "Bad HEAP allocation"   << std::endl;
     1443
     1444        exit(0);
     1445      }
     1446
     1447      break;
     1448    }
     1449
     1450    /////////////////////
     1451    case READ_HEAP_WRITE:       // add a entry in the heap
     1452    {
     1453      if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
     1454      {
     1455        HeapEntry heap_entry;
     1456        heap_entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
    12251457#if L1_MULTI_CACHE
    1226                     entry.owner.cache_id  = r_read_copy_cache.read();
    1227 #endif
    1228                     entry.owner.inst      = r_read_copy_inst.read();
    1229                     entry.count           = r_read_count.read();
    1230                 }
     1458        heap_entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
     1459#endif
     1460        heap_entry.owner.inst     = (m_cmd_read_trdid_fifo.read() & 0x2);
     1461
     1462        if(r_read_count.read() == 1) // creation of a new linked list
     1463        {
     1464          heap_entry.next         = m_heap.next_free_ptr();
     1465        }
     1466        else                         // head insertion in existing list
     1467        {
     1468          heap_entry.next         = r_read_ptr.read();
     1469        }
     1470        m_heap.write_free_entry(heap_entry);
     1471        m_heap.write_free_ptr(r_read_next_ptr.read());
     1472        if(r_read_last_free.read())  m_heap.set_full();
     1473
     1474        r_read_fsm = READ_RSP;
    12311475
    12321476#if DEBUG_MEMC_READ
    1233 if( m_debug_read_fsm )
    1234 {
    1235     std::cout << "  <MEMC " << name() << ".READ_DIR_HIT> Update directory entry:"
    1236               << " set = " << std::dec << set
    1237               << " / way = " << way
    1238               << " / owner_id = " << entry.owner.srcid
    1239               << " / owner_ins = " << entry.owner.inst
    1240               << " / count = " << entry.count
    1241               << " / is_cnt = " << entry.is_cnt << std::endl;
    1242 }
    1243 #endif
    1244 
    1245                 m_cache_directory.write(set, way, entry);
    1246                 r_read_fsm    = READ_RSP;
    1247             }
    1248             break;
    1249         }
    1250         ////////////////////
    1251         case READ_HEAP_LOCK:    // read data in cache, update the directory
    1252                                 // and prepare the HEAP update       
    1253         {
    1254             if( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
    1255             {
    1256                 // enter counter mode when we reach the limit of copies or the heap is full
    1257                 bool go_cnt = (r_read_count.read() >= r_copies_limit.read()) || m_heap.is_full();
    1258 
    1259                 // read data in the cache
    1260                 size_t set = m_y[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
    1261                 size_t way = r_read_way.read();
    1262                 for ( size_t i=0 ; i<m_words ; i++ ) r_read_data[i] = m_cache_data[way][set][i];
    1263 
    1264                 // update the cache directory
    1265                 DirectoryEntry entry;
    1266                 entry.valid       = true;
    1267                 entry.is_cnt  = go_cnt;
    1268                 entry.dirty       = r_read_dirty.read();
    1269                 entry.tag         = r_read_tag.read();
    1270                 entry.lock        = r_read_lock.read();
    1271                 entry.count   = r_read_count.read() + 1;
    1272 
    1273                 if (not go_cnt)        // Not entering counter mode
    1274                 {
    1275                     entry.owner.srcid   = r_read_copy.read();
     1477        if( m_debug_read_fsm )
     1478        {
     1479          std::cout
     1480            << "  <MEMC " << name() << ".READ_HEAP_WRITE> Add an entry in the heap:"
     1481            << " owner_id = " << heap_entry.owner.srcid
     1482            << " owner_ins = " << heap_entry.owner.inst << std::endl;
     1483        }
     1484#endif
     1485      }
     1486      else
     1487      {
     1488        std::cout
     1489          << "VCI_MEM_CACHE ERROR " << name()
     1490          << " READ_HEAP_WRITE state" << std::endl
     1491          << "Bad HEAP allocation" << std::endl;
     1492
     1493        exit(0);
     1494      }
     1495      break;
     1496    }
     1497
     1498    /////////////////////
     1499    case READ_HEAP_ERASE:
     1500    {
     1501      if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
     1502      {
     1503        HeapEntry next_entry = m_heap.read(r_read_ptr.read());
     1504        if( next_entry.next == r_read_ptr.read() )
     1505        {
     1506          r_read_fsm = READ_HEAP_LAST;
     1507        }
     1508        else
     1509        {
     1510          r_read_ptr = next_entry.next;
     1511          r_read_fsm = READ_HEAP_ERASE;
     1512        }
     1513      }
     1514      else
     1515      {
     1516        std::cout
     1517          << "VCI_MEM_CACHE ERROR " << name()
     1518          << " READ_HEAP_ERASE state" << std::endl
     1519          << "Bad HEAP allocation" << std::endl;
     1520
     1521        exit(0);
     1522      }
     1523      break;
     1524    }
     1525
     1526    ////////////////////
     1527    case READ_HEAP_LAST:
     1528    {
     1529      if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
     1530      {
     1531        HeapEntry last_entry;
     1532        last_entry.owner.srcid    = 0;
    12761533#if L1_MULTI_CACHE
    1277                     entry.owner.cache_id= r_read_copy_cache.read();
    1278 #endif
    1279                     entry.owner.inst    = r_read_copy_inst.read();
    1280                     entry.ptr           = m_heap.next_free_ptr();   // set pointer on the heap
    1281                 }
    1282                 else                // Entering Counter mode
    1283                 {
    1284                     entry.owner.srcid   = 0;
     1534        last_entry.owner.cache_id = 0;
     1535#endif
     1536        last_entry.owner.inst     = false;
     1537
     1538        if(m_heap.is_full())
     1539        {
     1540          last_entry.next       = r_read_ptr.read();
     1541          m_heap.unset_full();
     1542        }
     1543        else
     1544        {
     1545          last_entry.next       = r_read_next_ptr.read();
     1546        }
     1547        m_heap.write(r_read_ptr.read(),last_entry);
     1548        r_read_fsm = READ_RSP;
     1549      }
     1550      else
     1551      {
     1552        std::cout << "VCI_MEM_CACHE ERROR " << name()
     1553          << " READ_HEAP_LAST state" << std::endl;
     1554        std::cout << "Bad HEAP allocation" << std::endl;
     1555        exit(0);
     1556      }
     1557      break;
     1558    }
     1559
     1560    //////////////
     1561    case READ_RSP:    //  request the TGT_RSP FSM to return data
     1562    {
     1563      if( !r_read_to_tgt_rsp_req )
     1564      {
     1565        for ( size_t i=0 ; i<m_words ; i++ )  r_read_to_tgt_rsp_data[i] = r_read_data[i];
     1566        r_read_to_tgt_rsp_word   = m_x[(vci_addr_t)m_cmd_read_addr_fifo.read()];
     1567        r_read_to_tgt_rsp_length = m_cmd_read_length_fifo.read();
     1568        r_read_to_tgt_rsp_srcid  = m_cmd_read_srcid_fifo.read();
     1569        r_read_to_tgt_rsp_trdid  = m_cmd_read_trdid_fifo.read();
     1570        r_read_to_tgt_rsp_pktid  = m_cmd_read_pktid_fifo.read();
     1571        cmd_read_fifo_get    = true;
     1572        r_read_to_tgt_rsp_req  = true;
     1573        r_read_fsm     = READ_IDLE;
     1574
     1575#if DEBUG_MEMC_READ
     1576        if( m_debug_read_fsm )
     1577        {
     1578          std::cout << "  <MEMC " << name() << ".READ_RSP> Request the TGT_RSP FSM to return data:"
     1579            << " rsrcid = " << std::dec << m_cmd_read_srcid_fifo.read()
     1580            << " / address = " << std::hex << m_cmd_read_addr_fifo.read()
     1581            << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
     1582        }
     1583#endif
     1584      }
     1585      break;
     1586    }
     1587
     1588    ///////////////////
     1589    case READ_TRT_LOCK: // read miss : check the Transaction Table
     1590    {
     1591      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_READ )
     1592      {
     1593        size_t      index     = 0;
     1594        vci_addr_t  addr      = (vci_addr_t)m_cmd_read_addr_fifo.read();
     1595        bool        hit_read  = m_transaction_tab.hit_read(m_nline[addr], index);
     1596        bool        hit_write = m_transaction_tab.hit_write(m_nline[addr]);
     1597        bool        wok       = !m_transaction_tab.full(index);
     1598
     1599        if( hit_read || !wok || hit_write )  // missing line already requested or no space
     1600        {
     1601          if(!wok)      m_cpt_trt_full++;
     1602          if(hit_read || hit_write)   m_cpt_trt_rb++;
     1603          r_read_fsm = READ_IDLE;
     1604        }
     1605        else                  // missing line is requested to the XRAM
     1606        {
     1607          m_cpt_read_miss++;
     1608          r_read_trt_index = index;
     1609          r_read_fsm       = READ_TRT_SET;
     1610        }
     1611
     1612#if DEBUG_MEMC_READ
     1613        if( m_debug_read_fsm )
     1614        {
     1615          std::cout << "  <MEMC " << name() << ".READ_TRT_LOCK> Check TRT:"
     1616            << " hit_read = " << hit_read
     1617            << " / hit_write = " << hit_write
     1618            << " / full = " << !wok << std::endl;
     1619        }
     1620#endif
     1621      }
     1622      break;
     1623    }
     1624
     1625    //////////////////
     1626    case READ_TRT_SET:      // register get transaction in TRT
     1627    {
     1628      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_READ )
     1629      {
     1630        m_transaction_tab.set(r_read_trt_index.read(),
     1631            true,
     1632            m_nline[(vci_addr_t)(m_cmd_read_addr_fifo.read())],
     1633            m_cmd_read_srcid_fifo.read(),
     1634            m_cmd_read_trdid_fifo.read(),
     1635            m_cmd_read_pktid_fifo.read(),
     1636            true,
     1637            m_cmd_read_length_fifo.read(),
     1638            m_x[(vci_addr_t)(m_cmd_read_addr_fifo.read())],
     1639            std::vector<be_t>(m_words,0),
     1640            std::vector<data_t>(m_words,0));
     1641#if DEBUG_MEMC_READ
     1642        if( m_debug_read_fsm )
     1643        {
     1644          std::cout << "  <MEMC " << name() << ".READ_TRT_SET> Write in Transaction Table: " << std::hex
     1645            << " address = " << std::hex << m_cmd_read_addr_fifo.read()
     1646            << " / srcid = " << std::dec << m_cmd_read_srcid_fifo.read()
     1647            << std::endl;
     1648        }
     1649#endif
     1650        r_read_fsm = READ_TRT_REQ;
     1651      }
     1652      break;
     1653    }
     1654
     1655    //////////////////
     1656    case READ_TRT_REQ:
     1657    {
     1658      // consume the read request in the FIFO,
     1659      // and send it to the ixr_cmd_fsm
     1660
     1661      if( not r_read_to_ixr_cmd_req )
     1662      {
     1663        cmd_read_fifo_get       = true;
     1664        r_read_to_ixr_cmd_req   = true;
     1665        r_read_to_ixr_cmd_nline = m_nline[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
     1666        r_read_to_ixr_cmd_trdid = r_read_trt_index.read();
     1667        r_read_fsm              = READ_IDLE;
     1668
     1669#if DEBUG_MEMC_READ
     1670        if( m_debug_read_fsm )
     1671        {
     1672          std::cout
     1673            << "  <MEMC " << name() << ".READ_TRT_REQ> Request GET transaction for address "
     1674            << std::hex << m_cmd_read_addr_fifo.read() << std::endl;
     1675        }
     1676#endif
     1677      }
     1678      break;
     1679    }
     1680  } // end switch read_fsm
     1681
     1682  ///////////////////////////////////////////////////////////////////////////////////
     1683  //    WRITE FSM
     1684  ///////////////////////////////////////////////////////////////////////////////////
     1685  // The WRITE FSM handles the write bursts sent by the processors.
     1686  // All addresses in a burst must be in the same cache line.
     1687  // A complete write burst is consumed in the FIFO & copied to a local buffer.
     1688  // Then the FSM takes the lock protecting the cache directory, to check
     1689  // if the line is in the cache.
     1690  //
     1691  // - In case of HIT, the cache is updated.
     1692  //   If there is no other copy, an acknowledge response is immediately
     1693  //   returned to the writing processor.
     1694  //   If the data is cached by other processors, a coherence transaction must
     1695  //   be launched:
     1696  //   It is a multicast update if the line is not in counter mode, and the processor
     1697  //   takes the lock protecting the Update Table (UPT) to register this transaction.
     1698  //   It is a broadcast invalidate if the line is in counter mode.
     1699  //   If the UPT is full, it releases the lock(s) and retry. Then, it sends
     1700  //   a multi-update request to all owners of the line (but the writer),
     1701  //   through the INIT_CMD FSM. In case of coherence transaction, the WRITE FSM
     1702  //   does not respond to the writing processor, as this response will be sent by
     1703  //   the INIT_RSP FSM when all update responses have been received.
     1704  //
     1705  // - In case of MISS, the WRITE FSM takes the lock protecting the transaction
     1706  //   table (TRT). If a read transaction to the XRAM for this line already exists,
     1707  //   it writes in the TRT (write buffer). Otherwise, if a TRT entry is free,
     1708  //   the WRITE FSM register a new transaction in TRT, and sends a read line request
     1709  //   to the XRAM. If the TRT is full, it releases the lock, and waits.
     1710  //   Finally, the WRITE FSM returns an aknowledge response to the writing processor.
     1711  /////////////////////////////////////////////////////////////////////////////////////
     1712
     1713  switch ( r_write_fsm.read() )
     1714  {
     1715    ////////////////
     1716    case WRITE_IDLE:  // copy first word of a write burst in local buffer
     1717    {
     1718      if ( m_cmd_write_addr_fifo.rok() )
     1719      {
     1720        m_cpt_write++;
     1721        m_cpt_write_cells++;
     1722
     1723        // consume a word in the FIFO & write it in the local buffer
     1724        cmd_write_fifo_get  = true;
     1725        size_t index        = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
     1726
     1727        r_write_address     = (addr_t)(m_cmd_write_addr_fifo.read());
     1728        r_write_word_index  = index;
     1729        r_write_word_count  = 1;
     1730        r_write_data[index] = m_cmd_write_data_fifo.read();
     1731        r_write_srcid       = m_cmd_write_srcid_fifo.read();
     1732        r_write_trdid       = m_cmd_write_trdid_fifo.read();
     1733        r_write_pktid       = m_cmd_write_pktid_fifo.read();
     1734
     1735        // initialize the be field for all words
     1736        for ( size_t i=0 ; i<m_words ; i++ )
     1737        {
     1738          if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read();
     1739          else              r_write_be[i] = 0x0;
     1740        }
     1741
     1742        if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
     1743          r_write_byte = true;
     1744        else
     1745          r_write_byte = false;
     1746
     1747        if( m_cmd_write_eop_fifo.read() )
     1748        {
     1749          r_write_fsm = WRITE_DIR_REQ;
     1750        }
     1751        else
     1752        {
     1753          r_write_fsm = WRITE_NEXT;
     1754        }
     1755
     1756#if DEBUG_MEMC_WRITE
     1757        if( m_debug_write_fsm )
     1758        {
     1759          std::cout << "  <MEMC " << name() << ".WRITE_IDLE> Write request "
     1760            << " srcid = " << std::dec << m_cmd_write_srcid_fifo.read()
     1761            << " / address = " << std::hex << m_cmd_write_addr_fifo.read()
     1762            << " / data = " << m_cmd_write_data_fifo.read() << std::endl;
     1763        }
     1764#endif
     1765      }
     1766      break;
     1767    }
     1768
     1769    ////////////////
     1770    case WRITE_NEXT:  // copy next word of a write burst in local buffer
     1771    {
     1772      if ( m_cmd_write_addr_fifo.rok() )
     1773      {
     1774
     1775#if DEBUG_MEMC_WRITE
     1776        if( m_debug_write_fsm )
     1777        {
     1778          std::cout << "  <MEMC " << name() << ".WRITE_NEXT> Write another word in local buffer"
     1779                    << std::endl;
     1780        }
     1781#endif
     1782        m_cpt_write_cells++;
     1783
     1784        // check that the next word is in the same cache line
     1785        if (( m_nline[(vci_addr_t)(r_write_address.read())]       !=
     1786              m_nline[(vci_addr_t)(m_cmd_write_addr_fifo.read())] ))
     1787        {
     1788          std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_NEXT state" << std::endl
     1789                    << "all words in a write burst must be in same cache line" << std::endl;
     1790
     1791          exit(0);
     1792        }
     1793
     1794        // consume a word in the FIFO & write it in the local buffer
     1795        cmd_write_fifo_get  = true;
     1796        size_t index        = r_write_word_index.read() + r_write_word_count.read();
     1797
     1798        r_write_be[index]   = m_cmd_write_be_fifo.read();
     1799        r_write_data[index] = m_cmd_write_data_fifo.read();
     1800        r_write_word_count  = r_write_word_count.read() + 1;
     1801
     1802        if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
     1803          r_write_byte = true;
     1804
     1805        if ( m_cmd_write_eop_fifo.read() )
     1806        {
     1807          r_write_fsm = WRITE_DIR_REQ;
     1808        }
     1809      }
     1810      break;
     1811    }
     1812
     1813    ////////////////////
     1814    case WRITE_DIR_REQ:
     1815    // Get the lock to the directory
     1816    {
     1817      if ( r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE )
     1818      {
     1819        r_write_fsm = WRITE_DIR_LOCK;
     1820      }
     1821
     1822#if DEBUG_MEMC_WRITE
     1823      if( m_debug_write_fsm )
     1824      {
     1825        std::cout
     1826          << "  <MEMC " << name() << ".WRITE_DIR_REQ> Requesting DIR lock "
     1827          << std::endl;
     1828      }
     1829#endif
     1830
     1831      break;
     1832    }
     1833
     1834    ////////////////////
     1835    case WRITE_DIR_LOCK:
     1836    // access directory to check hit/miss
     1837    {
     1838      if ( r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE )
     1839      {
     1840        size_t  way = 0;
     1841        DirectoryEntry entry(m_cache_directory.read(r_write_address.read(), way));
     1842
     1843        if ( entry.valid ) // hit
     1844        {
     1845          // copy directory entry in local buffer in case of hit
     1846          r_write_is_cnt     = entry.is_cnt;
     1847          r_write_lock       = entry.lock;
     1848          r_write_tag        = entry.tag;
     1849          r_write_copy       = entry.owner.srcid;
    12851850#if L1_MULTI_CACHE
    1286                     entry.owner.cache_id= 0;
    1287 #endif
    1288                     entry.owner.inst    = false;
    1289                     entry.ptr           = 0;
    1290                 }
    1291 
    1292                 m_cache_directory.write(set, way, entry);
    1293 
    1294                 // prepare the heap update (add an entry, or clear the linked list)
    1295                 if (not go_cnt)     // not switching to counter mode
    1296                 {
    1297                     // We test if the next free entry in the heap is the last
    1298                     HeapEntry heap_entry = m_heap.next_free_entry();
    1299                     r_read_next_ptr      = heap_entry.next;
    1300                     r_read_last_free     = ( heap_entry.next == m_heap.next_free_ptr() );
    1301 
    1302                     r_read_fsm           = READ_HEAP_WRITE; // add an entry in the HEAP
    1303                 }
    1304                 else                    // switching to counter mode
    1305                 {
    1306                     if ( r_read_count.read()>1 )            // heap must be cleared
    1307                     {
    1308                         HeapEntry next_entry = m_heap.read(r_read_ptr.read());
    1309                         r_read_next_ptr      = m_heap.next_free_ptr();
    1310                         m_heap.write_free_ptr(r_read_ptr.read());
    1311 
    1312                         if( next_entry.next == r_read_ptr.read() )  // last entry
    1313                         {
    1314                             r_read_fsm = READ_HEAP_LAST;    // erase the entry
    1315                         }
    1316                         else                                        // not the last entry
    1317                         {
    1318                             r_read_ptr = next_entry.next;
    1319                             r_read_fsm = READ_HEAP_ERASE;   // erase the list
    1320                         }
    1321                     }
    1322                     else        // the heap is not used / nothing to do
    1323                     {
    1324                         r_read_fsm = READ_RSP;
    1325                     }
    1326                 }
    1327 
    1328 #if DEBUG_MEMC_READ
    1329 if( m_debug_read_fsm )
    1330 {
    1331     std::cout << "  <MEMC " << name() << ".READ_HEAP_LOCK> Update directory:"
    1332               << " tag = " << std::hex << entry.tag
    1333               << " set = " << std::dec << set
    1334               << " way = " << way
    1335               << " count = " << entry.count
    1336               << " is_cnt = " << entry.is_cnt << std::endl;
    1337 }
    1338 #endif
    1339             }
    1340             break;
    1341         }
    1342         /////////////////////
    1343         case READ_HEAP_WRITE:       // add a entry in the heap
    1344         {
    1345             if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
    1346             {
    1347                 HeapEntry heap_entry;
    1348                 heap_entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
     1851          r_write_copy_cache = entry.owner.cache_id;
     1852#endif
     1853          r_write_copy_inst  = entry.owner.inst;
     1854          r_write_count      = entry.count;
     1855          r_write_ptr        = entry.ptr;
     1856          r_write_way        = way;
     1857
     1858          if( entry.is_cnt && entry.count )
     1859          {
     1860            r_write_fsm = WRITE_DIR_READ;
     1861          }
     1862          else
     1863          {
     1864            if (r_write_byte.read())
     1865            {
     1866              r_write_fsm = WRITE_DIR_READ;
     1867            }
     1868            else
     1869            {
     1870              r_write_fsm = WRITE_DIR_HIT;
     1871            }
     1872          }
     1873        }
     1874        else  // miss
     1875        {
     1876          r_write_fsm = WRITE_MISS_TRT_LOCK;
     1877        }
     1878
     1879#if DEBUG_MEMC_WRITE
     1880        if( m_debug_write_fsm )
     1881        {
     1882          std::cout << "  <MEMC " << name() << ".WRITE_DIR_LOCK> Check the directory: "
     1883            << " address = " << std::hex << r_write_address.read()
     1884            << " hit = " << std::dec << entry.valid
     1885            << " count = " << entry.count
     1886            << " is_cnt = " << entry.is_cnt << std::endl;
     1887        }
     1888#endif
     1889      }
     1890      else
     1891      {
     1892        std::cout << "VCI_MEM_CACHE ERROR " << name()
     1893          << " WRITE_DIR_LOCK state"        << std::endl
     1894          << "bad DIR allocation"           << std::endl;
     1895
     1896        exit(0);
     1897      }
     1898
     1899      break;
     1900    }
     1901
     1902    ////////////////////
     1903    case WRITE_DIR_READ:  // read the cache and complete the buffer when be!=0xF
     1904    {
     1905      // update local buffer
     1906      size_t set  = m_y[(vci_addr_t)(r_write_address.read())];
     1907      size_t way  = r_write_way.read();
     1908      for(size_t i=0 ; i<m_words ; i++)
     1909      {
     1910        data_t mask = 0;
     1911        if  (r_write_be[i].read() & 0x1) mask = mask | 0x000000FF;
     1912        if  (r_write_be[i].read() & 0x2) mask = mask | 0x0000FF00;
     1913        if  (r_write_be[i].read() & 0x4) mask = mask | 0x00FF0000;
     1914        if  (r_write_be[i].read() & 0x8) mask = mask | 0xFF000000;
     1915
     1916        // complete only if mask is not null (for energy consumption)
     1917        if ( r_write_be[i].read() || r_write_is_cnt.read() )
     1918        {
     1919          r_write_data[i]  = (r_write_data[i].read() & mask) |
     1920            (m_cache_data[way][set][i] & ~mask);
     1921        }
     1922      } // end for
     1923
     1924      // test if a coherence broadcast is required
     1925      if( r_write_is_cnt.read() && r_write_count.read() )
     1926      {
     1927        r_write_fsm = WRITE_BC_TRT_LOCK;
     1928      }
     1929      else
     1930      {
     1931        r_write_fsm = WRITE_DIR_HIT;
     1932      }
     1933
     1934#if DEBUG_MEMC_WRITE
     1935      if( m_debug_write_fsm )
     1936      {
     1937        std::cout << "  <MEMC " << name() << ".WRITE_DIR_READ> Read the cache to complete local buffer" << std::endl;
     1938      }
     1939#endif
     1940      break;
     1941    }
     1942
     1943    ///////////////////
     1944    case WRITE_DIR_HIT:
     1945    {
     1946      // update the cache directory
     1947      // update directory with Dirty bit
     1948      DirectoryEntry entry;
     1949      entry.valid          = true;
     1950      entry.dirty          = true;
     1951      entry.tag          = r_write_tag.read();
     1952      entry.is_cnt         = r_write_is_cnt.read();
     1953      entry.lock           = r_write_lock.read();
     1954      entry.owner.srcid    = r_write_copy.read();
    13491955#if L1_MULTI_CACHE
    1350                 heap_entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
    1351 #endif
    1352                 heap_entry.owner.inst     = (m_cmd_read_trdid_fifo.read() & 0x2);
    1353 
    1354                 if(r_read_count.read() == 1)    // creation of a new linked list
    1355                 {
    1356                     heap_entry.next         = m_heap.next_free_ptr();
    1357                 }
    1358                 else                            // head insertion in existing list
    1359                 {
    1360                     heap_entry.next         = r_read_ptr.read();
    1361                 }
    1362                 m_heap.write_free_entry(heap_entry);
    1363                 m_heap.write_free_ptr(r_read_next_ptr.read());
    1364                 if(r_read_last_free.read())  m_heap.set_full();
    1365 
    1366                 r_read_fsm = READ_RSP;
    1367 
    1368 #if DEBUG_MEMC_READ
    1369 if( m_debug_read_fsm )
    1370 {
    1371     std::cout << "  <MEMC " << name() << ".READ_HEAP_WRITE> Add an entry in the heap:"
    1372               << " owner_id = " << heap_entry.owner.srcid
    1373               << " owner_ins = " << heap_entry.owner.inst << std::endl;
    1374 }
    1375 #endif
    1376             }
    1377             else
    1378             {
    1379                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    1380                           << " READ_HEAP_WRITE state" << std::endl;
    1381                 std::cout << "Bad HEAP allocation" << std::endl;
    1382                 exit(0);
    1383             }
    1384             break;
    1385         }
    1386         /////////////////////
    1387         case READ_HEAP_ERASE:
    1388         {
    1389             if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
    1390             {
    1391                 HeapEntry next_entry = m_heap.read(r_read_ptr.read());
    1392                 if( next_entry.next == r_read_ptr.read() )
    1393                 {
    1394                     r_read_fsm = READ_HEAP_LAST;
    1395                 }
    1396                 else
    1397                 {
    1398                     r_read_ptr = next_entry.next;
    1399                     r_read_fsm = READ_HEAP_ERASE;
    1400                 }
    1401             }
    1402             else
    1403             {
    1404                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    1405                           << " READ_HEAP_ERASE state" << std::endl;
    1406                 std::cout << "Bad HEAP allocation" << std::endl;
    1407                 exit(0);
    1408             }
    1409             break;
    1410         }
    1411         ////////////////////
    1412         case READ_HEAP_LAST:
    1413         {
    1414             if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
    1415             {
    1416                 HeapEntry last_entry;
    1417                 last_entry.owner.srcid    = 0;
     1956      entry.owner.cache_id = r_write_copy_cache.read();
     1957#endif
     1958      entry.owner.inst     = r_write_copy_inst.read();
     1959      entry.count          = r_write_count.read();
     1960      entry.ptr            = r_write_ptr.read();
     1961
     1962      size_t set           = m_y[(vci_addr_t)(r_write_address.read())];
     1963      size_t way           = r_write_way.read();
     1964
     1965      // update directory
     1966      m_cache_directory.write(set, way, entry);
     1967
     1968      // owner is true when the  the first registered copy is the writer itself
     1969      bool owner = (((r_write_copy.read() == r_write_srcid.read())
    14181970#if L1_MULTI_CACHE
    1419                 last_entry.owner.cache_id = 0;
    1420 #endif
    1421                 last_entry.owner.inst     = false;
    1422 
    1423                 if(m_heap.is_full())
    1424                 {
    1425                     last_entry.next       = r_read_ptr.read();
    1426                     m_heap.unset_full();
    1427                 }
    1428                 else
    1429                 {
    1430                     last_entry.next       = r_read_next_ptr.read();
    1431                 }
    1432                 m_heap.write(r_read_ptr.read(),last_entry);
    1433                 r_read_fsm = READ_RSP;
    1434             }
    1435             else
    1436             {
    1437                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    1438                           << " READ_HEAP_LAST state" << std::endl;
    1439                 std::cout << "Bad HEAP allocation" << std::endl;
    1440                 exit(0);
    1441             }
    1442             break;
    1443         }
    1444         //////////////
    1445         case READ_RSP:          //  request the TGT_RSP FSM to return data
    1446         {
    1447             if( !r_read_to_tgt_rsp_req )
    1448             {   
    1449                 for ( size_t i=0 ; i<m_words ; i++ )  r_read_to_tgt_rsp_data[i] = r_read_data[i];
    1450                 r_read_to_tgt_rsp_word   = m_x[(vci_addr_t)m_cmd_read_addr_fifo.read()];
    1451                 r_read_to_tgt_rsp_length = m_cmd_read_length_fifo.read();
    1452                 r_read_to_tgt_rsp_srcid  = m_cmd_read_srcid_fifo.read();
    1453                 r_read_to_tgt_rsp_trdid  = m_cmd_read_trdid_fifo.read();
    1454                 r_read_to_tgt_rsp_pktid  = m_cmd_read_pktid_fifo.read();
    1455                 cmd_read_fifo_get        = true;
    1456                 r_read_to_tgt_rsp_req    = true;
    1457                 r_read_fsm               = READ_IDLE; 
    1458 
    1459 #if DEBUG_MEMC_READ
    1460 if( m_debug_read_fsm )
    1461 {
    1462     std::cout << "  <MEMC " << name() << ".READ_RSP> Request the TGT_RSP FSM to return data:"
    1463               << " rsrcid = " << std::dec << m_cmd_read_srcid_fifo.read()
    1464               << " / address = " << std::hex << m_cmd_read_addr_fifo.read()
    1465               << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
    1466 }
    1467 #endif
    1468             }
    1469             break;
    1470         }
    1471         ///////////////////
    1472         case READ_TRT_LOCK:     // read miss : check the Transaction Table
    1473         {
    1474             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_READ )
    1475             {
    1476                 size_t      index     = 0;
    1477                 vci_addr_t  addr      = (vci_addr_t)m_cmd_read_addr_fifo.read();
    1478                 bool        hit_read  = m_transaction_tab.hit_read(m_nline[addr], index);
    1479                 bool        hit_write = m_transaction_tab.hit_write(m_nline[addr]);
    1480                 bool        wok       = !m_transaction_tab.full(index);
    1481 
    1482                 if( hit_read || !wok || hit_write )  // missing line already requested or no space
    1483                 {
    1484                     if(!wok)                    m_cpt_trt_full++;
    1485                     if(hit_read || hit_write)   m_cpt_trt_rb++;
    1486                     r_read_fsm = READ_IDLE;
    1487                 }
    1488                 else                                // missing line is requested to the XRAM
    1489                 {
    1490                     m_cpt_read_miss++;
    1491                     r_read_trt_index = index;
    1492                     r_read_fsm       = READ_TRT_SET;
    1493                 }
    1494 
    1495 #if DEBUG_MEMC_READ
    1496 if( m_debug_read_fsm )
    1497 {
    1498     std::cout << "  <MEMC " << name() << ".READ_TRT_LOCK> Check TRT:"
    1499               << " hit_read = " << hit_read
    1500               << " / hit_write = " << hit_write
    1501               << " / full = " << !wok << std::endl;
    1502 }
    1503 #endif
    1504             }
    1505             break;
    1506         }
    1507         //////////////////
    1508         case READ_TRT_SET:      // register get transaction in TRT
    1509         {
    1510             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_READ )
    1511             {
    1512                 m_transaction_tab.set(r_read_trt_index.read(),
    1513                                       true,
    1514                                       m_nline[(vci_addr_t)(m_cmd_read_addr_fifo.read())],
    1515                                       m_cmd_read_srcid_fifo.read(),
    1516                                       m_cmd_read_trdid_fifo.read(),
    1517                                       m_cmd_read_pktid_fifo.read(),
    1518                                       true,
    1519                                       m_cmd_read_length_fifo.read(),
    1520                                       m_x[(vci_addr_t)(m_cmd_read_addr_fifo.read())],
    1521                                       std::vector<be_t>(m_words,0),
    1522                                       std::vector<data_t>(m_words,0));
    1523 #if DEBUG_MEMC_READ
    1524 if( m_debug_read_fsm )
    1525 {
    1526     std::cout << "  <MEMC " << name() << ".READ_TRT_SET> Write in Transaction Table: " << std::hex
    1527               << " address = " << std::hex << m_cmd_read_addr_fifo.read()
    1528               << " / srcid = " << std::dec << m_cmd_read_srcid_fifo.read()
    1529               << std::endl;
    1530 }
    1531 #endif
    1532                 r_read_fsm = READ_TRT_REQ;
    1533             }
    1534             break;
    1535         }
    1536         //////////////////
    1537         case READ_TRT_REQ:              // consume the read request in the FIFO,
    1538                                                 // and send it to the ixr_cmd_fsm
    1539         {       
    1540             if( not r_read_to_ixr_cmd_req )
    1541             {
    1542                 cmd_read_fifo_get           = true;
    1543                 r_read_to_ixr_cmd_req   = true;
    1544                 r_read_to_ixr_cmd_nline = m_nline[(vci_addr_t)(m_cmd_read_addr_fifo.read())];
    1545                 r_read_to_ixr_cmd_trdid = r_read_trt_index.read();
    1546                 r_read_fsm                  = READ_IDLE;
    1547 
    1548 #if DEBUG_MEMC_READ
    1549 if( m_debug_read_fsm )
    1550 {
    1551     std::cout << "  <MEMC " << name() << ".READ_TRT_REQ> Request GET transaction for address "
    1552               << std::hex << m_cmd_read_addr_fifo.read() << std::endl;
    1553 }
    1554 #endif
    1555             }
    1556             break;
    1557         }
    1558     } // end switch read_fsm
    1559 
    1560     ///////////////////////////////////////////////////////////////////////////////////
    1561     //          WRITE FSM
    1562     ///////////////////////////////////////////////////////////////////////////////////
    1563     // The WRITE FSM handles the write bursts sent by the processors.
    1564     // All addresses in a burst must be in the same cache line.
    1565     // A complete write burst is consumed in the FIFO & copied to a local buffer.
    1566     // Then the FSM takes the lock protecting the cache directory, to check
    1567     // if the line is in the cache.
    1568     //
    1569     // - In case of HIT, the cache is updated.
    1570     //   If there is no other copy, an acknowledge response is immediately
    1571     //   returned to the writing processor.
    1572     //   If the data is cached by other processors, a coherence transaction must
    1573     //   be launched:
    1574     //   It is a multicast update if the line is not in counter mode, and the processor
    1575     //   takes the lock protecting the Update Table (UPT) to register this transaction.
    1576     //   It is a broadcast invalidate if the line is in counter mode.
    1577     //   If the UPT is full, it releases the lock(s) and retry. Then, it sends
    1578     //   a multi-update request to all owners of the line (but the writer),
    1579     //   through the INIT_CMD FSM. In case of coherence transaction, the WRITE FSM
    1580     //   does not respond to the writing processor, as this response will be sent by
    1581     //   the INIT_RSP FSM when all update responses have been received.
    1582     //
    1583     // - In case of MISS, the WRITE FSM takes the lock protecting the transaction
    1584     //   table (TRT). If a read transaction to the XRAM for this line already exists,
    1585     //   it writes in the TRT (write buffer). Otherwise, if a TRT entry is free,
    1586     //   the WRITE FSM register a new transaction in TRT, and sends a read line request
    1587     //   to the XRAM. If the TRT is full, it releases the lock, and waits.
    1588     //   Finally, the WRITE FSM returns an aknowledge response to the writing processor.
    1589     /////////////////////////////////////////////////////////////////////////////////////
    1590 
    1591     switch ( r_write_fsm.read() )
     1971            and (r_write_copy_cache.read()==r_write_pktid.read())
     1972#endif
     1973            ) and not r_write_copy_inst.read());
     1974
     1975      // no_update is true when there is no need for coherence transaction
     1976      bool no_update = (r_write_count.read()==0) || ( owner && (r_write_count.read()==1));
     1977
     1978      // write data in the cache if no coherence transaction
     1979      if( no_update )
     1980      {
     1981        for(size_t i=0 ; i<m_words ; i++)
     1982        {
     1983          if  ( r_write_be[i].read() )
     1984          {
     1985            m_cache_data[way][set][i]  = r_write_data[i].read();
     1986
     1987            if ( m_monitor_ok )
     1988            {
     1989              vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2;
     1990              char buf[80];
     1991              snprintf(buf, 80, "WRITE_DIR_HIT srcid %d", r_write_srcid.read());
     1992              check_monitor( buf, address, r_write_data[i].read() );
     1993            }
     1994          }
     1995        }
     1996      }
     1997
     1998      if ( owner and not no_update )
     1999      {
     2000        r_write_count = r_write_count.read() - 1;
     2001      }
     2002
     2003      if ( no_update )
     2004      // Write transaction completed
     2005      {
     2006        r_write_fsm = WRITE_RSP;
     2007      }
     2008      else
     2009      // coherence update required
     2010      {
     2011        if( !r_write_to_init_cmd_multi_req.read()   &&
     2012            !r_write_to_init_cmd_brdcast_req.read() )
     2013        {
     2014          r_write_fsm = WRITE_UPT_LOCK;
     2015        }
     2016        else
     2017        {
     2018          r_write_fsm = WRITE_WAIT;
     2019        }
     2020      }
     2021
     2022#if DEBUG_MEMC_WRITE
     2023      if( m_debug_write_fsm )
     2024      {
     2025        if ( no_update )
     2026        {
     2027          std::cout << "  <MEMC " << name() << ".WRITE_DIR_HIT> Write into cache / No coherence transaction"
     2028            << std::endl;
     2029        }
     2030        else
     2031        {
     2032          std::cout << "  <MEMC " << name() << ".WRITE_DIR_HIT> Coherence update required:"
     2033            << " is_cnt = " << r_write_is_cnt.read()
     2034            << " nb_copies = " << std::dec << r_write_count.read() << std::endl;
     2035          if (owner)
     2036            std::cout << "       ... but the first copy is the writer" << std::endl;
     2037        }
     2038      }
     2039#endif
     2040      break;
     2041    }
     2042
     2043      ////////////////////
     2044    case WRITE_UPT_LOCK:  // Try to register the update request in UPT
    15922045    {
    1593         ////////////////
    1594         case WRITE_IDLE:        // copy first word of a write burst in local buffer     
    1595         {
    1596             if ( m_cmd_write_addr_fifo.rok() )
    1597             {
    1598                 m_cpt_write++;
    1599                 m_cpt_write_cells++;
    1600 
    1601                 // consume a word in the FIFO & write it in the local buffer
    1602                 cmd_write_fifo_get      = true;
    1603                 size_t index            = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
    1604 
    1605                 r_write_address         = (addr_t)(m_cmd_write_addr_fifo.read());
    1606                 r_write_word_index      = index;
    1607                 r_write_word_count      = 1;
    1608                 r_write_data[index]     = m_cmd_write_data_fifo.read();
    1609                 r_write_srcid           = m_cmd_write_srcid_fifo.read();
    1610                 r_write_trdid           = m_cmd_write_trdid_fifo.read();
    1611                 r_write_pktid           = m_cmd_write_pktid_fifo.read();
    1612 
    1613                 // initialize the be field for all words
    1614                 for ( size_t i=0 ; i<m_words ; i++ )
    1615                 {
    1616                     if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read();
    1617                     else              r_write_be[i] = 0x0;
    1618                 }
    1619 
    1620                 if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
    1621                     r_write_byte = true;
    1622                 else   
    1623                     r_write_byte = false;
    1624 
    1625                 if( m_cmd_write_eop_fifo.read() )  r_write_fsm = WRITE_DIR_LOCK;
    1626                 else                               r_write_fsm = WRITE_NEXT;
     2046      if ( r_alloc_upt_fsm.read() == ALLOC_UPT_WRITE )
     2047      {
     2048        bool        wok        = false;
     2049        size_t      index      = 0;
     2050        size_t      srcid      = r_write_srcid.read();
     2051        size_t      trdid      = r_write_trdid.read();
     2052        size_t      pktid      = r_write_pktid.read();
     2053        addr_t      nline      = m_nline[(vci_addr_t)(r_write_address.read())];
     2054        size_t      nb_copies  = r_write_count.read();
     2055        size_t      set        = m_y[(vci_addr_t)(r_write_address.read())];
     2056        size_t      way        = r_write_way.read();
     2057
     2058        wok = m_update_tab.set(true,  // it's an update transaction
     2059            false,    // it's not a broadcast
     2060            true,     // it needs a response
     2061            srcid,
     2062            trdid,
     2063            pktid,
     2064            nline,
     2065            nb_copies,
     2066            index);
     2067        if ( wok )    // write data in cache
     2068        {
     2069          for(size_t i=0 ; i<m_words ; i++)
     2070          {
     2071            if ( r_write_be[i].read() )
     2072            {
     2073              m_cache_data[way][set][i] = r_write_data[i].read();
     2074
     2075              if ( m_monitor_ok )
     2076              {
     2077                vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2;
     2078                char buf[80];
     2079                snprintf(buf, 80, "WRITE_UPT_LOCK srcid %d", srcid);
     2080                check_monitor(buf, address, r_write_data[i].read() );
     2081              }
     2082            }
     2083          }
     2084        }
    16272085
    16282086#if DEBUG_MEMC_WRITE
    1629 if( m_debug_write_fsm )
    1630 {
    1631     std::cout << "  <MEMC " << name() << ".WRITE_IDLE> Write request "
     2087        if( m_debug_write_fsm )
     2088        {
     2089          if ( wok )
     2090          {
     2091            std::cout << "  <MEMC " << name() << ".WRITE_UPT_LOCK> Register the multicast update in UPT / "
     2092              << " nb_copies = " << r_write_count.read() << std::endl;
     2093          }
     2094        }
     2095#endif
     2096        r_write_upt_index = index;
     2097        //  releases the lock protecting UPT and the DIR if no entry...
     2098        if ( wok ) r_write_fsm = WRITE_UPT_HEAP_LOCK;
     2099        else       r_write_fsm = WRITE_WAIT;
     2100      }
     2101      break;
     2102    }
     2103
     2104      /////////////////////////
     2105    case WRITE_UPT_HEAP_LOCK:   // get access to heap
     2106    {
     2107      if( r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE )
     2108      {
     2109
     2110#if DEBUG_MEMC_WRITE
     2111        if( m_debug_write_fsm )
     2112        {
     2113          std::cout << "  <MEMC " << name() << ".WRITE_UPT_HEAP_LOCK> Get acces to the HEAP" << std::endl;
     2114        }
     2115#endif
     2116        r_write_fsm = WRITE_UPT_REQ;
     2117      }
     2118      break;
     2119    }
     2120
     2121    //////////////////
     2122    case WRITE_UPT_REQ:
     2123    {
     2124      // prepare the coherence ransaction for the INIT_CMD FSM
     2125      // and write the first copy in the FIFO
     2126      // send the request if only one copy
     2127
     2128      if( !r_write_to_init_cmd_multi_req.read() &&
     2129          !r_write_to_init_cmd_brdcast_req.read()  )  // no pending coherence request
     2130      {
     2131        r_write_to_init_cmd_brdcast_req  = false;
     2132        r_write_to_init_cmd_trdid        = r_write_upt_index.read();
     2133        r_write_to_init_cmd_nline        = m_nline[(vci_addr_t)(r_write_address.read())];
     2134        r_write_to_init_cmd_index        = r_write_word_index.read();
     2135        r_write_to_init_cmd_count        = r_write_word_count.read();
     2136
     2137        for(size_t i=0; i<m_words ; i++) r_write_to_init_cmd_be[i]=r_write_be[i].read();
     2138
     2139        size_t min = r_write_word_index.read();
     2140        size_t max = r_write_word_index.read() + r_write_word_count.read();
     2141        for (size_t i=min ; i<max ; i++) r_write_to_init_cmd_data[i] = r_write_data[i];
     2142
     2143        if( (r_write_copy.read() != r_write_srcid.read()) or
     2144#if L1_MULTI_CACHE
     2145            (r_write_copy_cache.read() != r_write_pktid.read()) or
     2146#endif
     2147            r_write_copy_inst.read() )
     2148        {
     2149          // put the first srcid in the fifo
     2150          write_to_init_cmd_fifo_put     = true;
     2151          write_to_init_cmd_fifo_inst    = r_write_copy_inst.read();
     2152          write_to_init_cmd_fifo_srcid   = r_write_copy.read();
     2153#if L1_MULTI_CACHE
     2154          write_to_init_cmd_fifo_cache_id= r_write_copy_cache.read();
     2155#endif
     2156          if(r_write_count.read() == 1)
     2157          {
     2158            r_write_fsm = WRITE_IDLE;
     2159            r_write_to_init_cmd_multi_req = true;
     2160          }
     2161          else
     2162          {
     2163            r_write_fsm = WRITE_UPT_NEXT;
     2164            r_write_to_dec = false;
     2165
     2166          }
     2167        }
     2168        else
     2169        {
     2170          r_write_fsm = WRITE_UPT_NEXT;
     2171          r_write_to_dec = false;
     2172        }
     2173
     2174#if DEBUG_MEMC_WRITE
     2175        if( m_debug_write_fsm )
     2176        {
     2177          std::cout << "  <MEMC " << name() << ".WRITE_UPT_REQ> Post first request to INIT_CMD FSM"
     2178            << " / srcid = " << std::dec << r_write_copy.read()
     2179            << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
     2180          if ( r_write_count.read() == 1)
     2181            std::cout << "         ... and this is the last" << std::endl;
     2182        }
     2183#endif
     2184      }
     2185      break;
     2186    }
     2187
     2188    ///////////////////
     2189    case WRITE_UPT_NEXT:
     2190    {
     2191      // continue the multi-update request to INIT_CMD fsm
     2192      // when there is copies in the heap.
     2193      // if one copy in the heap is the writer itself
     2194      // the corresponding SRCID should not be written in the fifo,
     2195      // but the UPT counter must be decremented.
     2196      // As this decrement is done in the WRITE_UPT_DEC state,
     2197      // after the last copy has been found, the decrement request
     2198      // must be  registered in the r_write_to_dec flip-flop.
     2199
     2200      HeapEntry entry = m_heap.read(r_write_ptr.read());
     2201
     2202      bool dec_upt_counter;
     2203
     2204      if( (entry.owner.srcid != r_write_srcid.read()) or
     2205#if L1_MULTI_CACHE
     2206          (entry.owner.cache_id != r_write_pktid.read()) or
     2207#endif
     2208          entry.owner.inst)               // put te next srcid in the fifo
     2209      {
     2210        dec_upt_counter                 = false;
     2211        write_to_init_cmd_fifo_put      = true;
     2212        write_to_init_cmd_fifo_inst     = entry.owner.inst;
     2213        write_to_init_cmd_fifo_srcid    = entry.owner.srcid;
     2214#if L1_MULTI_CACHE
     2215        write_to_init_cmd_fifo_cache_id = entry.owner.cache_id;
     2216#endif
     2217
     2218#if DEBUG_MEMC_WRITE
     2219        if( m_debug_write_fsm )
     2220        {
     2221          std::cout << "  <MEMC " << name() << ".WRITE_UPT_NEXT> Post another request to INIT_CMD FSM"
     2222            << " / heap_index = " << std::dec << r_write_ptr.read()
     2223            << " / srcid = " << std::dec << r_write_copy.read()
     2224            << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
     2225          if( entry.next == r_write_ptr.read() )
     2226            std::cout << "        ... and this is the last" << std::endl;
     2227        }
     2228#endif
     2229      }
     2230      else                                // the UPT counter must be decremented
     2231      {
     2232        dec_upt_counter = true;
     2233
     2234#if DEBUG_MEMC_WRITE
     2235        if( m_debug_write_fsm )
     2236        {
     2237          std::cout << "  <MEMC " << name() << ".WRITE_UPT_NEXT> Skip one entry in heap matching the writer"
     2238            << " / heap_index = " << std::dec << r_write_ptr.read()
     2239            << " / srcid = " << std::dec << r_write_copy.read()
     2240            << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
     2241          if( entry.next == r_write_ptr.read() )
     2242            std::cout << "        ... and this is the last" << std::endl;
     2243        }
     2244#endif
     2245      }
     2246
     2247      // register the possible UPT decrement request
     2248      r_write_to_dec = dec_upt_counter or r_write_to_dec.read();
     2249
     2250      if( not m_write_to_init_cmd_inst_fifo.wok() )
     2251      {
     2252        std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_UPT_NEXT state" << std::endl
     2253          << "The write_to_init_cmd_fifo should not be full" << std::endl
     2254          << "as the depth should be larger than the max number of copies" << std::endl;
     2255        exit(0);
     2256      }
     2257
     2258      r_write_ptr = entry.next;
     2259
     2260      if( entry.next == r_write_ptr.read() )  // last copy
     2261      {
     2262        r_write_to_init_cmd_multi_req = true;
     2263        if( r_write_to_dec.read() or dec_upt_counter)   r_write_fsm = WRITE_UPT_DEC;
     2264        else                                          r_write_fsm = WRITE_IDLE;
     2265      }
     2266      break;
     2267    }
     2268
     2269    //////////////////
     2270    case WRITE_UPT_DEC:
     2271    {
     2272      // If the initial writer has a copy, it should not
     2273      // receive an update request, but the counter in the
     2274      // update table must be decremented by the INIT_RSP FSM.
     2275
     2276      if ( !r_write_to_init_rsp_req.read() )
     2277      {
     2278        r_write_to_init_rsp_req = true;
     2279        r_write_to_init_rsp_upt_index = r_write_upt_index.read();
     2280        r_write_fsm = WRITE_IDLE;
     2281      }
     2282      break;
     2283    }
     2284   
     2285    ///////////////
     2286    case WRITE_RSP:
     2287    {
     2288      // Post a request to TGT_RSP FSM to acknowledge the write
     2289      // In order to increase the Write requests throughput,
     2290      // we don't wait to return in the IDLE state to consume
     2291      // a new request in the write FIFO
     2292
     2293      if ( !r_write_to_tgt_rsp_req.read() )
     2294      {
     2295        // post the request to TGT_RSP_FSM
     2296        r_write_to_tgt_rsp_req   = true;
     2297        r_write_to_tgt_rsp_srcid = r_write_srcid.read();
     2298        r_write_to_tgt_rsp_trdid = r_write_trdid.read();
     2299        r_write_to_tgt_rsp_pktid = r_write_pktid.read();
     2300
     2301        // try to get a new write request from the FIFO
     2302        if ( m_cmd_write_addr_fifo.rok() )
     2303        {
     2304          m_cpt_write++;
     2305          m_cpt_write_cells++;
     2306
     2307          // consume a word in the FIFO & write it in the local buffer
     2308          cmd_write_fifo_get  = true;
     2309          size_t index        = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
     2310
     2311          r_write_address     = (addr_t)(m_cmd_write_addr_fifo.read());
     2312          r_write_word_index  = index;
     2313          r_write_word_count  = 1;
     2314          r_write_data[index] = m_cmd_write_data_fifo.read();
     2315          r_write_srcid       = m_cmd_write_srcid_fifo.read();
     2316          r_write_trdid       = m_cmd_write_trdid_fifo.read();
     2317          r_write_pktid       = m_cmd_write_pktid_fifo.read();
     2318
     2319          // initialize the be field for all words
     2320          for ( size_t i=0 ; i<m_words ; i++ )
     2321          {
     2322            if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read();
     2323            else              r_write_be[i] = 0x0;
     2324          }
     2325
     2326          if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
     2327            r_write_byte = true;
     2328          else
     2329            r_write_byte = false;
     2330
     2331          if( m_cmd_write_eop_fifo.read() )
     2332          {
     2333            r_write_fsm = WRITE_DIR_REQ;
     2334          }
     2335          else
     2336          {
     2337            r_write_fsm = WRITE_NEXT;
     2338          }
     2339        }
     2340        else
     2341        {
     2342          r_write_fsm = WRITE_IDLE;
     2343        }
     2344
     2345#if DEBUG_MEMC_WRITE
     2346        if( m_debug_write_fsm )
     2347        {
     2348          std::cout << "  <MEMC " << name() << ".WRITE_RSP> Post a request to TGT_RSP FSM: rsrcid = "
     2349            << std::dec << r_write_srcid.read() << std::endl;
     2350          if ( m_cmd_write_addr_fifo.rok() )
     2351          {
     2352            std::cout << "                    New Write request: "
    16322353              << " srcid = " << std::dec << m_cmd_write_srcid_fifo.read()
    1633               << " / address = " << std::hex << m_cmd_write_addr_fifo.read() 
     2354              << " / address = " << std::hex << m_cmd_write_addr_fifo.read()
    16342355              << " / data = " << m_cmd_write_data_fifo.read() << std::endl;
    1635 }
    1636 #endif
    1637             }
    1638             break;
    1639         }
    1640         ////////////////
    1641         case WRITE_NEXT:        // copy next word of a write burst in local buffer
    1642         {
    1643             if ( m_cmd_write_addr_fifo.rok() )
    1644             {
     2356          }
     2357        }
     2358#endif
     2359      }
     2360      break;
     2361    }
     2362
     2363    /////////////////////////
     2364    case WRITE_MISS_TRT_LOCK: // Miss : check Transaction Table
     2365    {
     2366      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
     2367      {
    16452368
    16462369#if DEBUG_MEMC_WRITE
    1647 if( m_debug_write_fsm )
    1648 {
    1649     std::cout << "  <MEMC " << name() << ".WRITE_NEXT> Write another word in local buffer" << std::endl;
    1650 }
    1651 #endif
    1652                 m_cpt_write_cells++;
    1653 
    1654                 // check that the next word is in the same cache line
    1655                 if ( (m_nline[(vci_addr_t)(r_write_address.read())] !=
    1656                       m_nline[(vci_addr_t)(m_cmd_write_addr_fifo.read())]) )
    1657                 {
    1658                     std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_NEXT state" << std::endl;
    1659                     std::cout << "all words in a write burst must be in same cache line" << std::endl;
    1660                     exit(0);
    1661                 }
    1662 
    1663                 // consume a word in the FIFO & write it in the local buffer
    1664                 cmd_write_fifo_get=true;
    1665                 size_t index            = r_write_word_index.read() + r_write_word_count.read();
    1666 
    1667                 r_write_be[index]       = m_cmd_write_be_fifo.read();
    1668                 r_write_data[index]     = m_cmd_write_data_fifo.read();
    1669                 r_write_word_count      = r_write_word_count.read() + 1;
    1670 
    1671                 if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
    1672                     r_write_byte = true;
    1673 
    1674                 if ( m_cmd_write_eop_fifo.read() )  r_write_fsm = WRITE_DIR_LOCK;
    1675             }
    1676             break;
    1677         }
    1678         ////////////////////
    1679         case WRITE_DIR_LOCK:    // access directory to check hit/miss
    1680         {
    1681             if ( r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE )
    1682             {
    1683                 size_t  way = 0;
    1684                 DirectoryEntry entry(m_cache_directory.read(r_write_address.read(), way));
    1685 
    1686                 if ( entry.valid ) // hit
    1687                 {       
    1688                     // copy directory entry in local buffer in case of hit
    1689                     r_write_is_cnt     = entry.is_cnt;
    1690                     r_write_lock       = entry.lock;
    1691                     r_write_tag        = entry.tag;
    1692                     r_write_copy       = entry.owner.srcid;
     2370        if( m_debug_write_fsm )
     2371        {
     2372          std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_LOCK> Check the TRT" << std::endl;
     2373        }
     2374#endif
     2375        size_t    hit_index = 0;
     2376        size_t    wok_index = 0;
     2377        vci_addr_t  addr      = (vci_addr_t)r_write_address.read();
     2378        bool    hit_read  = m_transaction_tab.hit_read(m_nline[addr], hit_index);
     2379        bool    hit_write = m_transaction_tab.hit_write(m_nline[addr]);
     2380        bool    wok       = !m_transaction_tab.full(wok_index);
     2381
     2382        if ( hit_read )   // register the modified data in TRT
     2383        {
     2384          r_write_trt_index = hit_index;
     2385          r_write_fsm       = WRITE_MISS_TRT_DATA;
     2386          m_cpt_write_miss++;
     2387        }
     2388        else if ( wok && !hit_write )   // set a new entry in TRT
     2389        {
     2390          r_write_trt_index = wok_index;
     2391          r_write_fsm       = WRITE_MISS_TRT_SET;
     2392          m_cpt_write_miss++;
     2393        }
     2394        else    // wait an empty entry in TRT
     2395        {
     2396          r_write_fsm       = WRITE_WAIT;
     2397          m_cpt_trt_full++;
     2398        }
     2399      }
     2400      break;
     2401    }
     2402
     2403    ////////////////
     2404    case WRITE_WAIT:  // release the locks protecting the shared ressources
     2405    {
     2406#if DEBUG_MEMC_WRITE
     2407      if( m_debug_write_fsm )
     2408      {
     2409        std::cout << "  <MEMC " << name() << ".WRITE_WAIT> Releases the locks before retry" << std::endl;
     2410      }
     2411#endif
     2412      r_write_fsm = WRITE_DIR_REQ;
     2413      break;
     2414    }
     2415
     2416    ////////////////////////
     2417    case WRITE_MISS_TRT_SET:  // register a new transaction in TRT (Write Buffer)
     2418    {
     2419      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
     2420      {
     2421        std::vector<be_t>   be_vector;
     2422        std::vector<data_t> data_vector;
     2423        be_vector.clear();
     2424        data_vector.clear();
     2425        for ( size_t i=0; i<m_words; i++ )
     2426        {
     2427          be_vector.push_back(r_write_be[i]);
     2428          data_vector.push_back(r_write_data[i]);
     2429        }
     2430        m_transaction_tab.set(r_write_trt_index.read(),
     2431            true,     // read request to XRAM
     2432            m_nline[(vci_addr_t)(r_write_address.read())],
     2433            r_write_srcid.read(),
     2434            r_write_trdid.read(),
     2435            r_write_pktid.read(),
     2436            false,      // not a processor read
     2437            0,        // not a single word
     2438            0,            // word index
     2439            be_vector,
     2440            data_vector);
     2441        r_write_fsm = WRITE_MISS_XRAM_REQ;
     2442
     2443#if DEBUG_MEMC_WRITE
     2444        if( m_debug_write_fsm )
     2445        {
     2446          std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_SET> Set a new entry in TRT" << std::endl;
     2447        }
     2448#endif
     2449      }
     2450      break;
     2451    }
     2452
     2453      /////////////////////////
     2454    case WRITE_MISS_TRT_DATA: // update an entry in TRT (used as a Write Buffer)
     2455    {
     2456      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
     2457      {
     2458        std::vector<be_t> be_vector;
     2459        std::vector<data_t> data_vector;
     2460        be_vector.clear();
     2461        data_vector.clear();
     2462        for ( size_t i=0; i<m_words; i++ )
     2463        {
     2464          be_vector.push_back(r_write_be[i]);
     2465          data_vector.push_back(r_write_data[i]);
     2466        }
     2467        m_transaction_tab.write_data_mask(r_write_trt_index.read(),
     2468            be_vector,
     2469            data_vector);
     2470        r_write_fsm = WRITE_RSP;
     2471
     2472#if DEBUG_MEMC_WRITE
     2473        if( m_debug_write_fsm )
     2474        {
     2475          std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_DATA> Modify an existing entry in TRT" << std::endl;
     2476          m_transaction_tab.print( r_write_trt_index.read() );
     2477        }
     2478#endif
     2479      }
     2480      break;
     2481    }
     2482
     2483    /////////////////////////
     2484    case WRITE_MISS_XRAM_REQ: // send a GET request to IXR_CMD FSM
     2485    {
     2486      if ( !r_write_to_ixr_cmd_req )
     2487      {
     2488        r_write_to_ixr_cmd_req   = true;
     2489        r_write_to_ixr_cmd_write = false;
     2490        r_write_to_ixr_cmd_nline = m_nline[(vci_addr_t)(r_write_address.read())];
     2491        r_write_to_ixr_cmd_trdid = r_write_trt_index.read();
     2492        r_write_fsm              = WRITE_RSP;
     2493
     2494#if DEBUG_MEMC_WRITE
     2495        if( m_debug_write_fsm )
     2496        {
     2497          std::cout << "  <MEMC " << name() << ".WRITE_MISS_XRAM_REQ> Post a GET request to the IXR_CMD FSM" << std::endl;
     2498        }
     2499#endif
     2500      }
     2501      break;
     2502    }
     2503
     2504    ///////////////////////
     2505    case WRITE_BC_TRT_LOCK:     // Check TRT not full
     2506    {
     2507      if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
     2508      {
     2509        size_t wok_index = 0;
     2510        bool wok = !m_transaction_tab.full( wok_index );
     2511        if ( wok )    // set a new entry in TRT
     2512        {
     2513          r_write_trt_index = wok_index;
     2514          r_write_fsm       = WRITE_BC_UPT_LOCK;
     2515        }
     2516        else  // wait an empty entry in TRT
     2517        {
     2518          r_write_fsm       = WRITE_WAIT;
     2519        }
     2520
     2521#if DEBUG_MEMC_WRITE
     2522        if( m_debug_write_fsm )
     2523        {
     2524          std::cout << "  <MEMC " << name() << ".WRITE_BC_TRT_LOCK> Check TRT : wok = "
     2525            << wok << " / index = " << wok_index << std::endl;
     2526        }
     2527#endif
     2528      }
     2529      break;
     2530    }
     2531
     2532    //////////////////////
     2533    case WRITE_BC_UPT_LOCK:      // register BC transaction in UPT
     2534    {
     2535      if ( r_alloc_upt_fsm.read() == ALLOC_UPT_WRITE )
     2536      {
     2537        bool        wok       = false;
     2538        size_t      index     = 0;
     2539        size_t      srcid     = r_write_srcid.read();
     2540        size_t      trdid     = r_write_trdid.read();
     2541        size_t      pktid     = r_write_pktid.read();
     2542        addr_t      nline     = m_nline[(vci_addr_t)(r_write_address.read())];
     2543        size_t      nb_copies = r_write_count.read();
     2544
     2545        wok =m_update_tab.set(false,  // it's an inval transaction
     2546            true,     // it's a broadcast
     2547            true,     // it needs a response
     2548            srcid,
     2549            trdid,
     2550            pktid,
     2551            nline,
     2552            nb_copies,
     2553            index);
     2554
     2555#if DEBUG_MEMC_WRITE
     2556        if( m_debug_write_fsm )
     2557        {
     2558          if ( wok )
     2559          {
     2560            std::cout << "  <MEMC " << name() << ".WRITE_BC_UPT_LOCK> Register the broadcast inval in UPT / "
     2561              << " nb_copies = " << r_write_count.read() << std::endl;
     2562          }
     2563        }
     2564#endif
     2565        r_write_upt_index = index;
     2566
     2567        if ( wok ) r_write_fsm = WRITE_BC_DIR_INVAL;
     2568        else       r_write_fsm = WRITE_WAIT;
     2569      }
     2570      break;
     2571    }
     2572
     2573    ////////////////////////
     2574    case WRITE_BC_DIR_INVAL:
     2575    {
     2576      // Register a put transaction to XRAM in TRT
     2577      // and invalidate the line in directory
     2578      if ( (r_alloc_trt_fsm.read() != ALLOC_TRT_WRITE ) ||
     2579          (r_alloc_upt_fsm.read() != ALLOC_UPT_WRITE ) ||
     2580          (r_alloc_dir_fsm.read() != ALLOC_DIR_WRITE ) )
     2581      {
     2582        std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_BC_DIR_INVAL state" << std::endl;
     2583        std::cout << "bad TRT, DIR, or UPT allocation" << std::endl;
     2584        exit(0);
     2585      }
     2586
     2587      // register a write request to XRAM in TRT
     2588      m_transaction_tab.set(r_write_trt_index.read(),
     2589          false,    // write request to XRAM
     2590          m_nline[(vci_addr_t)(r_write_address.read())],
     2591          0,
     2592          0,
     2593          0,
     2594          false,    // not a processor read
     2595          0,        // not a single word
     2596          0,            // word index
     2597          std::vector<be_t>(m_words,0),
     2598          std::vector<data_t>(m_words,0));
     2599
     2600      // invalidate directory entry
     2601      DirectoryEntry entry;
     2602      entry.valid         = false;
     2603      entry.dirty         = false;
     2604      entry.tag         = 0;
     2605      entry.is_cnt        = false;
     2606      entry.lock          = false;
     2607      entry.owner.srcid   = 0;
    16932608#if L1_MULTI_CACHE
    1694                     r_write_copy_cache = entry.owner.cache_id;
    1695 #endif
    1696                     r_write_copy_inst  = entry.owner.inst;
    1697                     r_write_count      = entry.count;
    1698                     r_write_ptr        = entry.ptr;
    1699                     r_write_way        = way;
    1700 
    1701                     if( entry.is_cnt && entry.count )
    1702                     {
    1703                         r_write_fsm      = WRITE_DIR_READ;
    1704                     }
    1705                     else
    1706                     {
    1707                         if (r_write_byte.read())        r_write_fsm = WRITE_DIR_READ;
    1708                         else                                    r_write_fsm = WRITE_DIR_HIT;
    1709                     }
    1710                 }
    1711                 else    // miss
    1712                 {
    1713                     r_write_fsm = WRITE_MISS_TRT_LOCK;
    1714                 }
     2609      entry.owner.cache_id= 0;
     2610#endif
     2611      entry.owner.inst    = false;
     2612      entry.ptr           = 0;
     2613      entry.count         = 0;
     2614      size_t set          = m_y[(vci_addr_t)(r_write_address.read())];
     2615      size_t way          = r_write_way.read();
     2616
     2617      m_cache_directory.write(set, way, entry);
    17152618
    17162619#if DEBUG_MEMC_WRITE
    1717 if( m_debug_write_fsm )
    1718 {
    1719     std::cout << "  <MEMC " << name() << ".WRITE_DIR_LOCK> Check the directory: "
    1720               << " address = " << std::hex << r_write_address.read()
    1721               << " hit = " << std::dec << entry.valid
    1722               << " count = " << entry.count
    1723               << " is_cnt = " << entry.is_cnt << std::endl;
    1724 }
    1725 #endif
    1726             }
    1727             break;
    1728         }
    1729         ////////////////////
    1730         case WRITE_DIR_READ:    // read the cache and complete the buffer when be!=0xF
    1731         {
    1732             // update local buffer
    1733             size_t set  = m_y[(vci_addr_t)(r_write_address.read())];
    1734             size_t way  = r_write_way.read();
    1735             for(size_t i=0 ; i<m_words ; i++)
    1736             {
    1737                 data_t mask = 0;
    1738                 if  (r_write_be[i].read() & 0x1) mask = mask | 0x000000FF;
    1739                 if  (r_write_be[i].read() & 0x2) mask = mask | 0x0000FF00;
    1740                 if  (r_write_be[i].read() & 0x4) mask = mask | 0x00FF0000;
    1741                 if  (r_write_be[i].read() & 0x8) mask = mask | 0xFF000000;
    1742 
    1743                 // complete only if mask is not null (for energy consumption)
    1744                 if ( r_write_be[i].read() || r_write_is_cnt.read() )
    1745                 {
    1746                     r_write_data[i]  = (r_write_data[i].read() & mask) |
    1747                                        (m_cache_data[way][set][i] & ~mask);
    1748                 }
    1749             } // end for
    1750 
    1751             // test if a coherence broadcast is required
    1752             if( r_write_is_cnt.read() && r_write_count.read() ) r_write_fsm = WRITE_BC_TRT_LOCK;
    1753             else                                                                        r_write_fsm = WRITE_DIR_HIT;
     2620      if( m_debug_write_fsm )
     2621      {
     2622        std::cout << "  <MEMC " << name() << ".WRITE_BC_DIR_INVAL> Invalidate the directory entry: @ = "
     2623          << r_write_address.read() << " / register the put transaction in TRT:" << std::endl;
     2624      }
     2625#endif
     2626      r_write_fsm = WRITE_BC_CC_SEND;
     2627      break;
     2628    }
     2629
     2630    //////////////////////
     2631    case WRITE_BC_CC_SEND:    // Post a coherence broadcast request to INIT_CMD FSM
     2632    {
     2633      if ( !r_write_to_init_cmd_multi_req.read() && !r_write_to_init_cmd_brdcast_req.read() )
     2634      {
     2635        r_write_to_init_cmd_multi_req   = false;
     2636        r_write_to_init_cmd_brdcast_req = true;
     2637        r_write_to_init_cmd_trdid       = r_write_upt_index.read();
     2638        r_write_to_init_cmd_nline       = m_nline[(vci_addr_t)(r_write_address.read())];
     2639        r_write_to_init_cmd_index       = 0;
     2640        r_write_to_init_cmd_count       = 0;
     2641
     2642        for(size_t i=0; i<m_words ; i++)
     2643        {
     2644          r_write_to_init_cmd_be[i]=0;
     2645          r_write_to_init_cmd_data[i] = 0;
     2646        }
     2647        r_write_fsm = WRITE_BC_XRAM_REQ;
    17542648
    17552649#if DEBUG_MEMC_WRITE
    1756 if( m_debug_write_fsm )
    1757 {
    1758     std::cout << "  <MEMC " << name() << ".WRITE_DIR_READ> Read the cache to complete local buffer" << std::endl;
    1759 }
    1760 #endif
    1761             break;
    1762         }
    1763         ///////////////////
    1764         case WRITE_DIR_HIT:        // update the cache directory
    1765         {
    1766             // update directory with Dirty bit
    1767             DirectoryEntry entry;
    1768             entry.valid          = true;
    1769             entry.dirty          = true;
    1770             entry.tag            = r_write_tag.read();
    1771             entry.is_cnt         = r_write_is_cnt.read();
    1772             entry.lock           = r_write_lock.read();
    1773             entry.owner.srcid    = r_write_copy.read();
    1774 #if L1_MULTI_CACHE
    1775             entry.owner.cache_id = r_write_copy_cache.read();
    1776 #endif
    1777             entry.owner.inst     = r_write_copy_inst.read();
    1778             entry.count          = r_write_count.read();
    1779             entry.ptr            = r_write_ptr.read();
    1780             size_t set           = m_y[(vci_addr_t)(r_write_address.read())];
    1781             size_t way           = r_write_way.read();
    1782 
    1783             // update directory
    1784             m_cache_directory.write(set, way, entry);
    1785 
    1786             // owner is true when the  the first registered copy is the writer itself
    1787             bool owner = (((r_write_copy.read() == r_write_srcid.read())
    1788 #if L1_MULTI_CACHE
    1789                          and (r_write_copy_cache.read()==r_write_pktid.read())
    1790 #endif
    1791                          ) and not r_write_copy_inst.read());
    1792 
    1793             // no_update is true when there is no need for coherence transaction
    1794             bool no_update = (r_write_count.read()==0) || ( owner && (r_write_count.read()==1));
    1795 
    1796             // write data in the cache if no coherence transaction
    1797             if( no_update )
    1798             {
    1799                 for(size_t i=0 ; i<m_words ; i++)
    1800                 {
    1801                     if  ( r_write_be[i].read() )
    1802                     {
    1803                         m_cache_data[way][set][i]  = r_write_data[i].read();
    1804                        
    1805                         if ( m_monitor_ok )
    1806                         {
    1807                             vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2;
    1808                             char buf[80];
    1809                             snprintf(buf, 80, "WRITE_DIR_HIT srcid %d", r_write_srcid.read());
    1810                             check_monitor( buf, address, r_write_data[i].read() );
    1811                         }
    1812                     }
    1813                 }
    1814             }
    1815 
    1816             if ( owner and not no_update )   r_write_count = r_write_count.read() - 1;
    1817 
    1818             if ( no_update )      // Write transaction completed
    1819             {
    1820                 r_write_fsm = WRITE_RSP;
    1821             }
    1822             else          // coherence update required       
    1823             {
    1824                 if( !r_write_to_init_cmd_multi_req.read() &&
    1825                    !r_write_to_init_cmd_brdcast_req.read()  )   r_write_fsm = WRITE_UPT_LOCK;
    1826                 else                                                                r_write_fsm = WRITE_WAIT;
    1827             }
     2650        if( m_debug_write_fsm )
     2651        {
     2652          std::cout << "  <MEMC " << name() << ".WRITE_BC_CC_SEND> Post a broadcast request to INIT_CMD FSM" << std::endl;
     2653        }
     2654#endif
     2655      }
     2656      break;
     2657    }
     2658
     2659    ///////////////////////
     2660    case WRITE_BC_XRAM_REQ:   // Post a put request to IXR_CMD FSM
     2661    {
     2662      if ( !r_write_to_ixr_cmd_req )
     2663      {
     2664        r_write_to_ixr_cmd_req     = true;
     2665        r_write_to_ixr_cmd_write   = true;
     2666        r_write_to_ixr_cmd_nline   = m_nline[(vci_addr_t)(r_write_address.read())];
     2667        r_write_to_ixr_cmd_trdid   = r_write_trt_index.read();
     2668
     2669        for(size_t i=0; i<m_words; i++) r_write_to_ixr_cmd_data[i] = r_write_data[i];
     2670
     2671        r_write_fsm = WRITE_IDLE;
    18282672
    18292673#if DEBUG_MEMC_WRITE
    1830 if( m_debug_write_fsm )
    1831 {
    1832     if ( no_update )
    1833     {
    1834         std::cout << "  <MEMC " << name() << ".WRITE_DIR_HIT> Write into cache / No coherence transaction"
    1835                   << std::endl;
     2674        if( m_debug_write_fsm )
     2675        {
     2676          std::cout << "  <MEMC " << name() << ".WRITE_BC_XRAM_REQ> Post a put request to IXR_CMD FSM" << std::endl;
     2677        }
     2678#endif
     2679      }
     2680      break;
    18362681    }
    1837     else
    1838     {
    1839         std::cout << "  <MEMC " << name() << ".WRITE_DIR_HIT> Coherence update required:"
    1840                   << " is_cnt = " << r_write_is_cnt.read()
    1841                   << " nb_copies = " << std::dec << r_write_count.read() << std::endl;
    1842         if (owner)
    1843         std::cout << "       ... but the first copy is the writer" << std::endl;
    1844     }
    1845 }
    1846 #endif
    1847             break;
    1848         }
    1849         ////////////////////
    1850         case WRITE_UPT_LOCK:    // Try to register the update request in UPT
    1851         {
    1852             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_WRITE )
    1853             {
    1854                 bool        wok        = false;
    1855                 size_t      index      = 0;
    1856                 size_t      srcid      = r_write_srcid.read();
    1857                 size_t      trdid      = r_write_trdid.read();
    1858                 size_t      pktid      = r_write_pktid.read();
    1859                 addr_t      nline      = m_nline[(vci_addr_t)(r_write_address.read())];
    1860                 size_t      nb_copies  = r_write_count.read();
    1861                 size_t      set        = m_y[(vci_addr_t)(r_write_address.read())];
    1862                 size_t      way        = r_write_way.read();
    1863 
    1864                 wok = m_update_tab.set(true,    // it's an update transaction
    1865                                       false,    // it's not a broadcast
    1866                                       true,     // it needs a response
    1867                                       srcid,
    1868                                       trdid,
    1869                                       pktid,
    1870                                       nline,
    1871                                       nb_copies,
    1872                                       index);
    1873                 if ( wok )    // write data in cache
    1874                 {
    1875                     for(size_t i=0 ; i<m_words ; i++)
    1876                     {
    1877                         if ( r_write_be[i].read() )
    1878                         {
    1879                             m_cache_data[way][set][i] = r_write_data[i].read();
    1880 
    1881                             if ( m_monitor_ok )
    1882                             {
    1883                                 vci_addr_t address = (r_write_address.read() & ~(vci_addr_t)0x3F) | i<<2;
    1884                                 char buf[80];
    1885                                 snprintf(buf, 80, "WRITE_UPT_LOCK srcid %d", srcid);
    1886                                 check_monitor(buf, address, r_write_data[i].read() );
    1887                             }
    1888                         }
    1889                     }
    1890                 }
    1891 
    1892 #if DEBUG_MEMC_WRITE
    1893 if( m_debug_write_fsm )
    1894 {
    1895     if ( wok )
    1896     {
    1897         std::cout << "  <MEMC " << name() << ".WRITE_UPT_LOCK> Register the multicast update in UPT / "
    1898                   << " nb_copies = " << r_write_count.read() << std::endl;
    1899     }
    1900 }
    1901 #endif
    1902                 r_write_upt_index = index;
    1903                 //  releases the lock protecting UPT and the DIR if no entry...
    1904                 if ( wok ) r_write_fsm = WRITE_UPT_HEAP_LOCK;
    1905                 else       r_write_fsm = WRITE_WAIT;
    1906             }
    1907             break;
    1908         }
    1909         /////////////////////////
    1910         case WRITE_UPT_HEAP_LOCK:   // get access to heap
    1911         {
    1912             if( r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE )
    1913             {
    1914 
    1915 #if DEBUG_MEMC_WRITE
    1916 if( m_debug_write_fsm )
    1917 {
    1918     std::cout << "  <MEMC " << name() << ".WRITE_UPT_HEAP_LOCK> Get acces to the HEAP" << std::endl;
    1919 }
    1920 #endif
    1921                 r_write_fsm = WRITE_UPT_REQ;
    1922             }
    1923             break;
    1924         }
    1925         //////////////////
    1926         case WRITE_UPT_REQ:     //  prepare the coherence ransaction for the INIT_CMD FSM
    1927                                 //  and write the first copy in the FIFO
    1928                                 //  send the request if only one copy
    1929         {
    1930             if( !r_write_to_init_cmd_multi_req.read() &&
    1931                 !r_write_to_init_cmd_brdcast_req.read()  )  // no pending coherence request
    1932             {
    1933                 r_write_to_init_cmd_brdcast_req  = false;
    1934                 r_write_to_init_cmd_trdid        = r_write_upt_index.read();
    1935                 r_write_to_init_cmd_nline        = m_nline[(vci_addr_t)(r_write_address.read())];
    1936                 r_write_to_init_cmd_index        = r_write_word_index.read();
    1937                 r_write_to_init_cmd_count        = r_write_word_count.read();
    1938 
    1939                 for(size_t i=0; i<m_words ; i++) r_write_to_init_cmd_be[i]=r_write_be[i].read();
    1940 
    1941                 size_t min = r_write_word_index.read();
    1942                 size_t max = r_write_word_index.read() + r_write_word_count.read();
    1943                 for (size_t i=min ; i<max ; i++) r_write_to_init_cmd_data[i] = r_write_data[i];
    1944            
    1945                 if( (r_write_copy.read() != r_write_srcid.read()) or
    1946 #if L1_MULTI_CACHE
    1947                     (r_write_copy_cache.read() != r_write_pktid.read()) or
    1948 #endif
    1949                     r_write_copy_inst.read() )
    1950                 {
    1951                     // put the first srcid in the fifo
    1952                     write_to_init_cmd_fifo_put     = true;
    1953                     write_to_init_cmd_fifo_inst    = r_write_copy_inst.read();
    1954                     write_to_init_cmd_fifo_srcid   = r_write_copy.read();
    1955 #if L1_MULTI_CACHE
    1956                     write_to_init_cmd_fifo_cache_id= r_write_copy_cache.read();
    1957 #endif
    1958                     if(r_write_count.read() == 1)
    1959                     {
    1960                         r_write_fsm = WRITE_IDLE;
    1961                         r_write_to_init_cmd_multi_req = true;
    1962                     }
    1963                     else
    1964                     {
    1965                         r_write_fsm = WRITE_UPT_NEXT;
    1966                         r_write_to_dec = false;
    1967 
    1968                     }
    1969                 }
    1970                 else
    1971                 {
    1972                     r_write_fsm = WRITE_UPT_NEXT;
    1973                     r_write_to_dec = false;
    1974                 }
    1975 
    1976 #if DEBUG_MEMC_WRITE
    1977 if( m_debug_write_fsm )
    1978 {
    1979     std::cout << "  <MEMC " << name() << ".WRITE_UPT_REQ> Post first request to INIT_CMD FSM"
    1980               << " / srcid = " << std::dec << r_write_copy.read()
    1981               << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
    1982     if ( r_write_count.read() == 1)
    1983     std::cout << "         ... and this is the last" << std::endl;
    1984 }
    1985 #endif
    1986             }
    1987             break;
    1988         }
    1989         ///////////////////
    1990         case WRITE_UPT_NEXT:    // continue the multi-update request to INIT_CMD fsm
    1991                                 // when there is copies in the heap.
    1992                                 // if one copy in the heap is the writer itself
    1993                                 // the corresponding SRCID should not be written in the fifo,
    1994                                 // but the UPT counter must be decremented.
    1995                                 // As this decrement is done in the WRITE_UPT_DEC state,
    1996                                 // after the last copy has been found, the decrement request
    1997                                 // must be  registered in the r_write_to_dec flip-flop.
    1998         {
    1999             HeapEntry entry = m_heap.read(r_write_ptr.read());
    2000          
    2001             bool dec_upt_counter;
    2002 
    2003             if( (entry.owner.srcid != r_write_srcid.read()) or
    2004 #if L1_MULTI_CACHE
    2005                 (entry.owner.cache_id != r_write_pktid.read()) or
    2006 #endif
    2007                 entry.owner.inst)               // put te next srcid in the fifo
    2008             {
    2009                 dec_upt_counter                 = false;
    2010                 write_to_init_cmd_fifo_put      = true;
    2011                 write_to_init_cmd_fifo_inst     = entry.owner.inst;
    2012                 write_to_init_cmd_fifo_srcid    = entry.owner.srcid;
    2013 #if L1_MULTI_CACHE
    2014                 write_to_init_cmd_fifo_cache_id = entry.owner.cache_id;
    2015 #endif
    2016 
    2017 #if DEBUG_MEMC_WRITE
    2018 if( m_debug_write_fsm )
    2019 {
    2020     std::cout << "  <MEMC " << name() << ".WRITE_UPT_NEXT> Post another request to INIT_CMD FSM"
    2021               << " / heap_index = " << std::dec << r_write_ptr.read()
    2022               << " / srcid = " << std::dec << r_write_copy.read()
    2023               << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
    2024     if( entry.next == r_write_ptr.read() )
    2025     std::cout << "        ... and this is the last" << std::endl;
    2026 }
    2027 #endif
    2028             }
    2029             else                                // the UPT counter must be decremented
    2030             {
    2031                 dec_upt_counter = true;
    2032 
    2033 #if DEBUG_MEMC_WRITE
    2034 if( m_debug_write_fsm )
    2035 {
    2036     std::cout << "  <MEMC " << name() << ".WRITE_UPT_NEXT> Skip one entry in heap matching the writer"
    2037               << " / heap_index = " << std::dec << r_write_ptr.read()
    2038               << " / srcid = " << std::dec << r_write_copy.read()
    2039               << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
    2040     if( entry.next == r_write_ptr.read() )
    2041     std::cout << "        ... and this is the last" << std::endl;
    2042 }
    2043 #endif
    2044             }
    2045 
    2046             // register the possible UPT decrement request
    2047             r_write_to_dec = dec_upt_counter or r_write_to_dec.read();
    2048 
    2049             if( not m_write_to_init_cmd_inst_fifo.wok() )
    2050             {
    2051                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_UPT_NEXT state" << std::endl
    2052                           << "The write_to_init_cmd_fifo should not be full" << std::endl
    2053                           << "as the depth should be larger than the max number of copies" << std::endl;
    2054                 exit(0);
    2055             }
    2056 
    2057             r_write_ptr = entry.next;
    2058 
    2059             if( entry.next == r_write_ptr.read() )  // last copy
    2060             {
    2061                 r_write_to_init_cmd_multi_req = true;
    2062                 if( r_write_to_dec.read() or dec_upt_counter)   r_write_fsm = WRITE_UPT_DEC;
    2063                 else                                                r_write_fsm = WRITE_IDLE;
    2064             }
    2065             break;
    2066         }
    2067         //////////////////
    2068         case WRITE_UPT_DEC:     // If the initial writer has a copy, it should not
    2069                                 // receive an update request, but the counter in the
    2070                                 // update table must be decremented by the INIT_RSP FSM.
    2071         {
    2072             if ( !r_write_to_init_rsp_req.read() )
    2073             {
    2074                 r_write_to_init_rsp_req = true;
    2075                 r_write_to_init_rsp_upt_index = r_write_upt_index.read();
    2076                 r_write_fsm = WRITE_IDLE;
    2077             }
    2078             break;
    2079         }
    2080         ///////////////
    2081         case WRITE_RSP:         // Post a request to TGT_RSP FSM to acknowledge the write
    2082                             // In order to increase the Write requests throughput,
    2083                             // we don't wait to return in the IDLE state to consume
    2084                             // a new request in the write FIFO
    2085         {
    2086             if ( !r_write_to_tgt_rsp_req.read() )
    2087             {
    2088                 // post the request to TGT_RSP_FSM
    2089                 r_write_to_tgt_rsp_req   = true;
    2090                 r_write_to_tgt_rsp_srcid = r_write_srcid.read();
    2091                 r_write_to_tgt_rsp_trdid = r_write_trdid.read();
    2092                 r_write_to_tgt_rsp_pktid = r_write_pktid.read();
    2093 
    2094                 // try to get a new write request from the FIFO
    2095                 if ( m_cmd_write_addr_fifo.rok() )
    2096                 {
    2097                     m_cpt_write++;
    2098                     m_cpt_write_cells++;
    2099 
    2100                     // consume a word in the FIFO & write it in the local buffer
    2101                     cmd_write_fifo_get  = true;
    2102                     size_t index                = m_x[(vci_addr_t)(m_cmd_write_addr_fifo.read())];
    2103 
    2104                     r_write_address             = (addr_t)(m_cmd_write_addr_fifo.read());
    2105                     r_write_word_index  = index;
    2106                     r_write_word_count  = 1;
    2107                     r_write_data[index] = m_cmd_write_data_fifo.read();
    2108                     r_write_srcid               = m_cmd_write_srcid_fifo.read();
    2109                     r_write_trdid               = m_cmd_write_trdid_fifo.read();
    2110                     r_write_pktid               = m_cmd_write_pktid_fifo.read();
    2111 
    2112                     // initialize the be field for all words
    2113                     for ( size_t i=0 ; i<m_words ; i++ )
    2114                     {
    2115                         if ( i == index ) r_write_be[i] = m_cmd_write_be_fifo.read();
    2116                         else              r_write_be[i] = 0x0;
    2117                     }
    2118 
    2119                     if( !((m_cmd_write_be_fifo.read() == 0x0)||(m_cmd_write_be_fifo.read() == 0xF)) )
    2120                         r_write_byte = true;
    2121                     else   
    2122                         r_write_byte = false;
    2123 
    2124                     if( m_cmd_write_eop_fifo.read() )  r_write_fsm = WRITE_DIR_LOCK;
    2125                     else                               r_write_fsm = WRITE_NEXT;
    2126                 }
    2127                 else
    2128                 {
    2129                     r_write_fsm              = WRITE_IDLE;
    2130                 }
    2131 
    2132 #if DEBUG_MEMC_WRITE
    2133 if( m_debug_write_fsm )
    2134 {
    2135     std::cout << "  <MEMC " << name() << ".WRITE_RSP> Post a request to TGT_RSP FSM: rsrcid = "
    2136               << std::dec << r_write_srcid.read() << std::endl;
    2137     if ( m_cmd_write_addr_fifo.rok() )
    2138     {
    2139         std::cout << "                    New Write request: "
    2140               << " srcid = " << std::dec << m_cmd_write_srcid_fifo.read()
    2141               << " / address = " << std::hex << m_cmd_write_addr_fifo.read()
    2142               << " / data = " << m_cmd_write_data_fifo.read() << std::endl;
    2143     }
    2144 }
    2145 #endif
    2146             }
    2147             break;
    2148         }
    2149         /////////////////////////
    2150         case WRITE_MISS_TRT_LOCK:       // Miss : check Transaction Table
    2151         {
    2152             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
    2153             {
    2154 
    2155 #if DEBUG_MEMC_WRITE
    2156 if( m_debug_write_fsm )
    2157 {
    2158     std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_LOCK> Check the TRT" << std::endl;
    2159 }
    2160 #endif
    2161                 size_t          hit_index = 0;
    2162                 size_t          wok_index = 0;
    2163                 vci_addr_t      addr      = (vci_addr_t)r_write_address.read();
    2164                 bool            hit_read  = m_transaction_tab.hit_read(m_nline[addr], hit_index);
    2165                 bool            hit_write = m_transaction_tab.hit_write(m_nline[addr]);
    2166                 bool            wok       = !m_transaction_tab.full(wok_index);
    2167 
    2168                 if ( hit_read )         // register the modified data in TRT
    2169                 {
    2170                     r_write_trt_index = hit_index;
    2171                     r_write_fsm       = WRITE_MISS_TRT_DATA;
    2172                     m_cpt_write_miss++;
    2173                 }
    2174                 else if ( wok && !hit_write )   // set a new entry in TRT
    2175                 {
    2176                     r_write_trt_index = wok_index;
    2177                     r_write_fsm       = WRITE_MISS_TRT_SET;
    2178                     m_cpt_write_miss++;
    2179                 }
    2180                 else            // wait an empty entry in TRT
    2181                 {
    2182                     r_write_fsm       = WRITE_WAIT;
    2183                     m_cpt_trt_full++;
    2184                 }
    2185             }
    2186             break;
    2187         }
    2188         ////////////////
    2189         case WRITE_WAIT:        // release the locks protecting the shared ressources
    2190         {
    2191 
    2192 #if DEBUG_MEMC_WRITE
    2193 if( m_debug_write_fsm )
    2194 {
    2195     std::cout << "  <MEMC " << name() << ".WRITE_WAIT> Releases the locks before retry" << std::endl;
    2196 }
    2197 #endif
    2198             r_write_fsm = WRITE_DIR_LOCK;
    2199             break;
    2200         }
    2201         ////////////////////////
    2202         case WRITE_MISS_TRT_SET:        // register a new transaction in TRT (Write Buffer)
    2203         { 
    2204             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
    2205             {
    2206                 std::vector<be_t>       be_vector;
    2207                 std::vector<data_t> data_vector;
    2208                 be_vector.clear();
    2209                 data_vector.clear();
    2210                 for ( size_t i=0; i<m_words; i++ )
    2211                 {
    2212                     be_vector.push_back(r_write_be[i]);
    2213                     data_vector.push_back(r_write_data[i]);
    2214                 }
    2215                 m_transaction_tab.set(r_write_trt_index.read(),
    2216                                       true,                     // read request to XRAM
    2217                                       m_nline[(vci_addr_t)(r_write_address.read())],
    2218                                       r_write_srcid.read(),
    2219                                       r_write_trdid.read(),
    2220                                       r_write_pktid.read(),
    2221                                       false,                    // not a processor read
    2222                                       0,                        // not a single word
    2223                                       0,                        // word index
    2224                                       be_vector,
    2225                                       data_vector);
    2226                 r_write_fsm = WRITE_MISS_XRAM_REQ;
    2227 
    2228 #if DEBUG_MEMC_WRITE
    2229 if( m_debug_write_fsm )
    2230 {
    2231     std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_SET> Set a new entry in TRT" << std::endl;
    2232 }
    2233 #endif
    2234             }
    2235             break;
    2236         } 
    2237         /////////////////////////
    2238         case WRITE_MISS_TRT_DATA:       // update an entry in TRT (used as a Write Buffer)
    2239         {
    2240             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
    2241             {
    2242                 std::vector<be_t> be_vector;
    2243                 std::vector<data_t> data_vector;
    2244                 be_vector.clear();
    2245                 data_vector.clear();
    2246                 for ( size_t i=0; i<m_words; i++ )
    2247                 {
    2248                     be_vector.push_back(r_write_be[i]);
    2249                     data_vector.push_back(r_write_data[i]);
    2250                 }
    2251                 m_transaction_tab.write_data_mask(r_write_trt_index.read(),
    2252                                                   be_vector,
    2253                                                   data_vector);
    2254                 r_write_fsm = WRITE_RSP;
    2255 
    2256 #if DEBUG_MEMC_WRITE
    2257 if( m_debug_write_fsm )
    2258 {
    2259     std::cout << "  <MEMC " << name() << ".WRITE_MISS_TRT_DATA> Modify an existing entry in TRT" << std::endl;
    2260     m_transaction_tab.print( r_write_trt_index.read() );
    2261 }
    2262 #endif
    2263             }
    2264             break;
    2265         }
    2266         /////////////////////////
    2267         case WRITE_MISS_XRAM_REQ:       // send a GET request to IXR_CMD FSM
    2268         { 
    2269             if ( !r_write_to_ixr_cmd_req )
    2270             {
    2271                 r_write_to_ixr_cmd_req   = true;
    2272                 r_write_to_ixr_cmd_write = false;
    2273                 r_write_to_ixr_cmd_nline = m_nline[(vci_addr_t)(r_write_address.read())];
    2274                 r_write_to_ixr_cmd_trdid = r_write_trt_index.read();
    2275                 r_write_fsm              = WRITE_RSP;
    2276 
    2277 #if DEBUG_MEMC_WRITE
    2278 if( m_debug_write_fsm )
    2279 {
    2280     std::cout << "  <MEMC " << name() << ".WRITE_MISS_XRAM_REQ> Post a GET request to the IXR_CMD FSM" << std::endl;
    2281 }
    2282 #endif
    2283             }
    2284             break;
    2285         }
    2286         ///////////////////////
    2287         case WRITE_BC_TRT_LOCK:     // Check TRT not full
    2288         {
    2289             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE )
    2290             {
    2291                 size_t wok_index = 0;
    2292                 bool wok = !m_transaction_tab.full( wok_index );
    2293                 if ( wok )      // set a new entry in TRT
    2294                 {
    2295                     r_write_trt_index = wok_index;
    2296                     r_write_fsm       = WRITE_BC_UPT_LOCK;
    2297                 }
    2298                 else    // wait an empty entry in TRT
    2299                 {
    2300                     r_write_fsm       = WRITE_WAIT;
    2301                 }
    2302 
    2303 #if DEBUG_MEMC_WRITE
    2304 if( m_debug_write_fsm )
    2305 {
    2306     std::cout << "  <MEMC " << name() << ".WRITE_BC_TRT_LOCK> Check TRT : wok = "
    2307               << wok << " / index = " << wok_index << std::endl;
    2308 }
    2309 #endif
    2310             }
    2311             break;
    2312         }
    2313         //////////////////////
    2314         case WRITE_BC_UPT_LOCK:      // register BC transaction in UPT
    2315         {
    2316             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_WRITE )
    2317             {
    2318                 bool        wok       = false;
    2319                 size_t      index     = 0;
    2320                 size_t      srcid     = r_write_srcid.read();
    2321                 size_t      trdid     = r_write_trdid.read();
    2322                 size_t      pktid     = r_write_pktid.read();
    2323                 addr_t      nline     = m_nline[(vci_addr_t)(r_write_address.read())];
    2324                 size_t      nb_copies = r_write_count.read();
    2325 
    2326                 wok =m_update_tab.set(false,    // it's an inval transaction
    2327                                       true,     // it's a broadcast
    2328                                       true,     // it needs a response
    2329                                       srcid,
    2330                                       trdid,
    2331                                       pktid,
    2332                                       nline,
    2333                                       nb_copies,
    2334                                       index);
    2335 
    2336 #if DEBUG_MEMC_WRITE
    2337 if( m_debug_write_fsm )
    2338 {
    2339     if ( wok )
    2340     {
    2341         std::cout << "  <MEMC " << name() << ".WRITE_BC_UPT_LOCK> Register the broadcast inval in UPT / "
    2342                   << " nb_copies = " << r_write_count.read() << std::endl;
    2343     }
    2344 }
    2345 #endif
    2346                 r_write_upt_index = index;
    2347 
    2348                 if ( wok ) r_write_fsm = WRITE_BC_DIR_INVAL;
    2349                 else       r_write_fsm = WRITE_WAIT;
    2350             }
    2351             break;
    2352         }
    2353         ////////////////////////
    2354         case WRITE_BC_DIR_INVAL:        // Register a put transaction to XRAM in TRT
    2355                                 // and invalidate the line in directory
    2356         {
    2357             if ( (r_alloc_trt_fsm.read() != ALLOC_TRT_WRITE ) ||
    2358                  (r_alloc_upt_fsm.read() != ALLOC_UPT_WRITE ) ||
    2359                  (r_alloc_dir_fsm.read() != ALLOC_DIR_WRITE ) )
    2360             {
    2361                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_BC_DIR_INVAL state" << std::endl;
    2362                 std::cout << "bad TRT, DIR, or UPT allocation" << std::endl;
    2363                 exit(0);
    2364             }
    2365 
    2366             // register a write request to XRAM in TRT
    2367             m_transaction_tab.set(r_write_trt_index.read(),
    2368                                   false,                // write request to XRAM
    2369                                   m_nline[(vci_addr_t)(r_write_address.read())],
    2370                                   0,
    2371                                   0,
    2372                                   0,
    2373                                   false,                // not a processor read
    2374                                   0,                    // not a single word
    2375                                   0,                    // word index
    2376                                   std::vector<be_t>(m_words,0),
    2377                                   std::vector<data_t>(m_words,0));
    2378             // invalidate directory entry
    2379             DirectoryEntry entry;
    2380             entry.valid         = false;
    2381             entry.dirty         = false;
    2382             entry.tag           = 0;
    2383             entry.is_cnt        = false;
    2384             entry.lock          = false;
    2385             entry.owner.srcid   = 0;
    2386 #if L1_MULTI_CACHE
    2387             entry.owner.cache_id= 0;
    2388 #endif
    2389             entry.owner.inst    = false;
    2390             entry.ptr           = 0;
    2391             entry.count         = 0;
    2392             size_t set          = m_y[(vci_addr_t)(r_write_address.read())];
    2393             size_t way          = r_write_way.read();
    2394 
    2395             m_cache_directory.write(set, way, entry);
    2396 
    2397 #if DEBUG_MEMC_WRITE
    2398 if( m_debug_write_fsm )
    2399 {
    2400     std::cout << "  <MEMC " << name() << ".WRITE_BC_DIR_INVAL> Invalidate the directory entry: @ = "
    2401               << r_write_address.read() << " / register the put transaction in TRT:" << std::endl;
    2402 }
    2403 #endif
    2404             r_write_fsm = WRITE_BC_CC_SEND;
    2405             break;
    2406         }
    2407         //////////////////////
    2408         case WRITE_BC_CC_SEND:    // Post a coherence broadcast request to INIT_CMD FSM
    2409         {
    2410             if ( !r_write_to_init_cmd_multi_req.read() && !r_write_to_init_cmd_brdcast_req.read() )
    2411             {
    2412                 r_write_to_init_cmd_multi_req   = false;
    2413                 r_write_to_init_cmd_brdcast_req = true;
    2414                 r_write_to_init_cmd_trdid       = r_write_upt_index.read();
    2415                 r_write_to_init_cmd_nline       = m_nline[(vci_addr_t)(r_write_address.read())];
    2416                 r_write_to_init_cmd_index       = 0;
    2417                 r_write_to_init_cmd_count       = 0;
    2418 
    2419                 for(size_t i=0; i<m_words ; i++)
    2420                 {
    2421                     r_write_to_init_cmd_be[i]=0;
    2422                     r_write_to_init_cmd_data[i] = 0;
    2423                 }
    2424                 r_write_fsm = WRITE_BC_XRAM_REQ;
    2425 
    2426 #if DEBUG_MEMC_WRITE
    2427 if( m_debug_write_fsm )
    2428 {
    2429     std::cout << "  <MEMC " << name() << ".WRITE_BC_CC_SEND> Post a broadcast request to INIT_CMD FSM" << std::endl;
    2430 }
    2431 #endif
    2432             }
    2433             break;
    2434         }
    2435         ///////////////////////
    2436         case WRITE_BC_XRAM_REQ:   // Post a put request to IXR_CMD FSM
    2437         {
    2438             if ( !r_write_to_ixr_cmd_req )
    2439             {
    2440                 r_write_to_ixr_cmd_req     = true;
    2441                 r_write_to_ixr_cmd_write   = true;
    2442                 r_write_to_ixr_cmd_nline   = m_nline[(vci_addr_t)(r_write_address.read())];
    2443                 r_write_to_ixr_cmd_trdid   = r_write_trt_index.read();
    2444 
    2445                 for(size_t i=0; i<m_words; i++) r_write_to_ixr_cmd_data[i] = r_write_data[i];
    2446 
    2447                 r_write_fsm = WRITE_IDLE;
    2448 
    2449 #if DEBUG_MEMC_WRITE
    2450 if( m_debug_write_fsm )
    2451 {
    2452     std::cout << "  <MEMC " << name() << ".WRITE_BC_XRAM_REQ> Post a put request to IXR_CMD FSM" << std::endl;
    2453 }
    2454 #endif
    2455             }
    2456             break;
    2457         }
    2458     } // end switch r_write_fsm
     2682  } // end switch r_write_fsm
    24592683
    24602684    ///////////////////////////////////////////////////////////////////////
    2461     //          IXR_CMD FSM
     2685    //    IXR_CMD FSM
    24622686    ///////////////////////////////////////////////////////////////////////
    24632687    // The IXR_CMD fsm controls the command packets to the XRAM :
    24642688    // - It sends a single cell VCI read request to the XRAM in case of MISS
    2465     // posted by the READ, WRITE or SC FSMs : the TRDID field contains 
     2689    // posted by the READ, WRITE or SC FSMs : the TRDID field contains
    24662690    // the Transaction Tab index.
    24672691    // The VCI response is a multi-cell packet : the N cells contain
    24682692    // the N data words.
    24692693    // - It sends a multi-cell VCI write when the XRAM_RSP FSM, WRITE FSM
    2470     // or SC FSM request to save a dirty line to the XRAM. 
     2694    // or SC FSM request to save a dirty line to the XRAM.
    24712695    // The VCI response is a single cell packet.
    2472     // This FSM handles requests from the READ, WRITE, SC & XRAM_RSP FSMs 
     2696    // This FSM handles requests from the READ, WRITE, SC & XRAM_RSP FSMs
    24732697    // with a round-robin priority.
    24742698    ////////////////////////////////////////////////////////////////////////
    24752699
    2476     switch ( r_ixr_cmd_fsm.read() ) 
     2700    switch ( r_ixr_cmd_fsm.read() )
    24772701    {
    2478         //////////////////////// 
     2702        ////////////////////////
    24792703        case IXR_CMD_READ_IDLE:
    24802704        if      ( r_write_to_ixr_cmd_req )     r_ixr_cmd_fsm = IXR_CMD_WRITE_NLINE;
     
    24832707        else if ( r_read_to_ixr_cmd_req  )     r_ixr_cmd_fsm = IXR_CMD_READ_NLINE;
    24842708        break;
    2485         //////////////////////// 
     2709        ////////////////////////
    24862710        case IXR_CMD_WRITE_IDLE:
    24872711        if      ( r_sc_to_ixr_cmd_req  )       r_ixr_cmd_fsm = IXR_CMD_SC_NLINE;
     
    24902714        else if ( r_write_to_ixr_cmd_req )     r_ixr_cmd_fsm = IXR_CMD_WRITE_NLINE;
    24912715        break;
    2492         //////////////////////// 
     2716        ////////////////////////
    24932717        case IXR_CMD_SC_IDLE:
    24942718        if      ( r_xram_rsp_to_ixr_cmd_req  ) r_ixr_cmd_fsm = IXR_CMD_XRAM_DATA;
     
    24972721        else if ( r_sc_to_ixr_cmd_req  )       r_ixr_cmd_fsm = IXR_CMD_SC_NLINE;
    24982722        break;
    2499         //////////////////////// 
     2723        ////////////////////////
    25002724        case IXR_CMD_XRAM_IDLE:
    25012725        if      ( r_read_to_ixr_cmd_req  )     r_ixr_cmd_fsm = IXR_CMD_READ_NLINE;
     
    25062730        /////////////////////////       // send a get request to XRAM
    25072731        case IXR_CMD_READ_NLINE:
    2508         if ( p_vci_ixr.cmdack ) 
    2509         {
    2510             r_ixr_cmd_fsm = IXR_CMD_READ_IDLE;         
     2732        if ( p_vci_ixr.cmdack )
     2733        {
     2734            r_ixr_cmd_fsm = IXR_CMD_READ_IDLE;
    25112735            r_read_to_ixr_cmd_req = false;
    25122736
     
    25202744        break;
    25212745        //////////////////////////
    2522         case IXR_CMD_WRITE_NLINE:           // send a put or get command to XRAM
    2523         if ( p_vci_ixr.cmdack ) 
     2746        case IXR_CMD_WRITE_NLINE:     // send a put or get command to XRAM
     2747        if ( p_vci_ixr.cmdack )
    25242748        {
    25252749            if( r_write_to_ixr_cmd_write.read())
    25262750            {
    2527                 if ( r_ixr_cmd_cpt.read() == (m_words - 1) ) 
     2751                if ( r_ixr_cmd_cpt.read() == (m_words - 1) )
    25282752                {
    25292753                    r_ixr_cmd_cpt = 0;
    25302754                    r_ixr_cmd_fsm = IXR_CMD_WRITE_IDLE;
    25312755                    r_write_to_ixr_cmd_req = false;
    2532                 } 
    2533                 else 
     2756                }
     2757                else
    25342758                {
    25352759                    r_ixr_cmd_cpt = r_ixr_cmd_cpt + 1;
     
    25422766}
    25432767#endif
    2544             } 
    2545             else 
    2546             {
    2547                 r_ixr_cmd_fsm = IXR_CMD_WRITE_IDLE;             
     2768            }
     2769            else
     2770            {
     2771                r_ixr_cmd_fsm = IXR_CMD_WRITE_IDLE;
    25482772                r_write_to_ixr_cmd_req = false;
    25492773
     
    25592783        //////////////////////
    25602784        case IXR_CMD_SC_NLINE:      // send a put or get command to XRAM
    2561         if ( p_vci_ixr.cmdack ) 
     2785        if ( p_vci_ixr.cmdack )
    25622786        {
    25632787            if( r_sc_to_ixr_cmd_write.read())
    25642788            {
    2565                 if ( r_ixr_cmd_cpt.read() == (m_words - 1) ) 
     2789                if ( r_ixr_cmd_cpt.read() == (m_words - 1) )
    25662790                {
    25672791                    r_ixr_cmd_cpt = 0;
    25682792                    r_ixr_cmd_fsm = IXR_CMD_SC_IDLE;
    25692793                    r_sc_to_ixr_cmd_req = false;
    2570                 } 
    2571                 else 
     2794                }
     2795                else
    25722796                {
    25732797                    r_ixr_cmd_cpt = r_ixr_cmd_cpt + 1;
     
    25802804}
    25812805#endif
    2582             } 
    2583             else 
    2584             {
    2585                 r_ixr_cmd_fsm = IXR_CMD_SC_IDLE;               
     2806            }
     2807            else
     2808            {
     2809                r_ixr_cmd_fsm = IXR_CMD_SC_IDLE;
    25862810                r_sc_to_ixr_cmd_req = false;
    25872811
     
    25972821        ////////////////////////
    25982822        case IXR_CMD_XRAM_DATA:     // send a put command to XRAM
    2599         if ( p_vci_ixr.cmdack ) 
    2600         {
    2601             if ( r_ixr_cmd_cpt.read() == (m_words - 1) ) 
     2823        if ( p_vci_ixr.cmdack )
     2824        {
     2825            if ( r_ixr_cmd_cpt.read() == (m_words - 1) )
    26022826            {
    26032827                r_ixr_cmd_cpt = 0;
    26042828                r_ixr_cmd_fsm = IXR_CMD_XRAM_IDLE;
    26052829                r_xram_rsp_to_ixr_cmd_req = false;
    2606             } 
    2607             else 
     2830            }
     2831            else
    26082832            {
    26092833                r_ixr_cmd_cpt = r_ixr_cmd_cpt + 1;
     
    26312855    // The FSM takes the lock protecting the TRT, and the corresponding
    26322856    // entry is erased.
    2633     // 
     2857    //
    26342858    // - A response to a get request is a multi-cell VCI packet.
    26352859    // The Transaction Tab index is contained in the RTRDID field.
     
    26402864    ///////////////////////////////////////////////////////////////////////////////
    26412865
    2642     switch ( r_ixr_rsp_fsm.read() ) 
     2866    switch ( r_ixr_rsp_fsm.read() )
    26432867    {
    26442868        //////////////////
    2645         case IXR_RSP_IDLE:      // test if it's a get or a put transaction
    2646         {
    2647             if ( p_vci_ixr.rspval.read() ) 
     2869        case IXR_RSP_IDLE:  // test if it's a get or a put transaction
     2870        {
     2871            if ( p_vci_ixr.rspval.read() )
    26482872            {
    26492873                r_ixr_rsp_cpt   = 0;
     
    26542878
    26552879#if DEBUG_MEMC_IXR_RSP
    2656 if( m_debug_ixr_rsp_fsm ) 
     2880if( m_debug_ixr_rsp_fsm )
    26572881{
    2658     std::cout << "  <MEMC " << name() << ".IXR_RSP_IDLE> Response from XRAM to a put transaction" << std::endl; 
     2882    std::cout << "  <MEMC " << name() << ".IXR_RSP_IDLE> Response from XRAM to a put transaction" << std::endl;
    26592883}
    26602884#endif
    26612885                }
    2662                 else                                                           // get transaction
     2886                else                     // get transaction
    26632887                {
    2664                     r_ixr_rsp_fsm = IXR_RSP_TRT_READ;
    2665 
    2666 #if DEBUG_MEMC_IXR_RSP
    2667 if( m_debug_ixr_rsp_fsm )
    2668 {
    2669     std::cout << "  <MEMC " << name() << ".IXR_RSP_IDLE> Response from XRAM to a get transaction" << std::endl;
    2670 }
    2671 #endif
    2672                 }
    2673             }
    2674             break; 
    2675         }
    2676         ////////////////////////
    2677         case IXR_RSP_ACK:        // Aknowledge the VCI response
    2678         {
    2679             if(p_vci_ixr.rspval.read()) r_ixr_rsp_fsm = IXR_RSP_TRT_ERASE;
    2680 
    2681 #if DEBUG_MEMC_IXR_RSP
    2682 if( m_debug_ixr_rsp_fsm )
    2683 {
    2684     std::cout << "  <MEMC " << name() << ".IXR_RSP_ACK>" << std::endl;
    2685 }
    2686 #endif
    2687             break;
    2688         }
    2689         ////////////////////////
    2690         case IXR_RSP_TRT_ERASE:         // erase the entry in the TRT
    2691         {
    2692             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP )
    2693             {
    2694                 m_transaction_tab.erase(r_ixr_rsp_trt_index.read());
    2695                 r_ixr_rsp_fsm = IXR_RSP_IDLE;
     2888          r_ixr_rsp_fsm = IXR_RSP_TRT_READ;
    26962889
    26972890#if DEBUG_MEMC_IXR_RSP
    26982891if( m_debug_ixr_rsp_fsm )
    26992892{
    2700     std::cout << "  <MEMC " << name() << ".IXR_RSP_TRT_ERASE> Erase TRT entry "
    2701               << r_ixr_rsp_trt_index.read() << std::endl;
     2893    std::cout << "  <MEMC " << name() << ".IXR_RSP_IDLE> Response from XRAM to a get transaction" << std::endl;
    27022894}
    27032895#endif
     2896                }
    27042897            }
    27052898            break;
    27062899        }
     2900        ////////////////////////
     2901        case IXR_RSP_ACK:        // Aknowledge the VCI response
     2902        {
     2903            if(p_vci_ixr.rspval.read()) r_ixr_rsp_fsm = IXR_RSP_TRT_ERASE;
     2904
     2905#if DEBUG_MEMC_IXR_RSP
     2906if( m_debug_ixr_rsp_fsm )
     2907{
     2908    std::cout << "  <MEMC " << name() << ".IXR_RSP_ACK>" << std::endl;
     2909}
     2910#endif
     2911            break;
     2912        }
     2913        ////////////////////////
     2914        case IXR_RSP_TRT_ERASE:   // erase the entry in the TRT
     2915        {
     2916            if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP )
     2917            {
     2918                m_transaction_tab.erase(r_ixr_rsp_trt_index.read());
     2919                r_ixr_rsp_fsm = IXR_RSP_IDLE;
     2920
     2921#if DEBUG_MEMC_IXR_RSP
     2922if( m_debug_ixr_rsp_fsm )
     2923{
     2924    std::cout << "  <MEMC " << name() << ".IXR_RSP_TRT_ERASE> Erase TRT entry "
     2925              << r_ixr_rsp_trt_index.read() << std::endl;
     2926}
     2927#endif
     2928            }
     2929            break;
     2930        }
    27072931        ///////////////////////
    2708         case IXR_RSP_TRT_READ:          // write data in the TRT
    2709         {
    2710             if ( (r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP) &&  p_vci_ixr.rspval ) 
     2932        case IXR_RSP_TRT_READ:    // write data in the TRT
     2933        {
     2934            if ( (r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP) &&  p_vci_ixr.rspval )
    27112935            {
    27122936                size_t index    = r_ixr_rsp_trt_index.read();
    2713                 bool   eop      = p_vci_ixr.reop.read();
    2714                 data_t data     = p_vci_ixr.rdata.read();
     2937                bool   eop    = p_vci_ixr.reop.read();
     2938                data_t data   = p_vci_ixr.rdata.read();
    27152939                bool   error    = ((p_vci_ixr.rerror.read() & 0x1) == 1);
    2716                 assert(((eop == (r_ixr_rsp_cpt.read() == (m_words-1))) || p_vci_ixr.rerror.read()) 
     2940                assert(((eop == (r_ixr_rsp_cpt.read() == (m_words-1))) || p_vci_ixr.rerror.read())
    27172941                    and "Error in VCI_MEM_CACHE : invalid length for a response from XRAM");
    2718                 m_transaction_tab.write_rsp(index, 
    2719                                             r_ixr_rsp_cpt.read(), 
    2720                                             data, 
     2942                m_transaction_tab.write_rsp(index,
     2943                                            r_ixr_rsp_cpt.read(),
     2944                                            data,
    27212945                                            error);
    27222946                r_ixr_rsp_cpt = r_ixr_rsp_cpt.read() + 1;
    2723                 if ( eop ) 
     2947                if ( eop )
    27242948                {
    27252949                    r_ixr_rsp_to_xram_rsp_rok[r_ixr_rsp_trt_index.read()]=true;
     
    27512975    // a round-robin priority...
    27522976    //
    2753     // When a response is available, the corresponding TRT entry 
    2754     // must be copied in a local buffer to be written in the cache. 
     2977    // When a response is available, the corresponding TRT entry
     2978    // must be copied in a local buffer to be written in the cache.
    27552979    // The FSM takes the lock protecting the TRT, and the lock protecting the DIR.
    27562980    // It selects a cache slot and writes the line in the cache.
     
    27592983    // If there is no empty slot, a victim line is evicted, and
    27602984    // invalidate requests are sent to the L1 caches containing copies.
    2761     // If this line is dirty, the XRAM_RSP FSM send a request to the IXR_CMD 
     2985    // If this line is dirty, the XRAM_RSP FSM send a request to the IXR_CMD
    27622986    // FSM to save the victim line to the XRAM, and register the write transaction
    27632987    // in the TRT (using the entry previously used by the read transaction).
    27642988    ///////////////////////////////////////////////////////////////////////////////
    27652989
    2766     switch ( r_xram_rsp_fsm.read() ) 
     2990    switch ( r_xram_rsp_fsm.read() )
    27672991    {
    27682992        ///////////////////
    2769         case XRAM_RSP_IDLE:     // scan the XRAM responses to get the TRT index (round robin)
     2993        case XRAM_RSP_IDLE: // scan the XRAM responses to get the TRT index (round robin)
    27702994        {
    27712995            size_t ptr   = r_xram_rsp_trt_index.read();
     
    27763000                if ( r_ixr_rsp_to_xram_rsp_rok[index] )
    27773001                {
    2778                     r_xram_rsp_trt_index                = index;
    2779                     r_ixr_rsp_to_xram_rsp_rok[index]    = false;
    2780                     r_xram_rsp_fsm                      = XRAM_RSP_DIR_LOCK;
     3002                    r_xram_rsp_trt_index             = index;
     3003                    r_ixr_rsp_to_xram_rsp_rok[index] = false;
     3004                    r_xram_rsp_fsm                   = XRAM_RSP_DIR_LOCK;
    27813005
    27823006#if DEBUG_MEMC_XRAM_RSP
    27833007if( m_debug_xram_rsp_fsm )
    2784 {       
     3008{
    27853009    std::cout << "  <MEMC " << name() << ".XRAM_RSP_IDLE> Available cache line in TRT:"
    27863010              << " index = " << std::dec << index << std::endl;
     
    27903014                }
    27913015            }
    2792             break; 
     3016            break;
    27933017        }
    27943018        ///////////////////////
    2795         case XRAM_RSP_DIR_LOCK:         // Takes the lock on the directory
    2796         {
    2797             if( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP )
    2798             {
     3019        case XRAM_RSP_DIR_LOCK:
     3020        // Takes the lock on the directory
     3021        // Takes the lock on TRT
     3022        // Copy the TRT entry in a local buffer
     3023        {
     3024            if (( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP ) &&
     3025                ( r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP ))
     3026            {
     3027                // copy the TRT entry in the r_xram_rsp_trt_buf local buffer
     3028                size_t  index = r_xram_rsp_trt_index.read();
     3029
     3030                TransactionTabEntry trt_entry(m_transaction_tab.read(index));
     3031                r_xram_rsp_trt_buf.copy(trt_entry);  // TRT entry local buffer
     3032
    27993033                r_xram_rsp_fsm = XRAM_RSP_TRT_COPY;
    28003034
    28013035#if DEBUG_MEMC_XRAM_RSP
    28023036if( m_debug_xram_rsp_fsm )
    2803 {       
     3037{
    28043038    std::cout << "  <MEMC " << name() << ".XRAM_RSP_DIR_LOCK> Get access to directory" << std::endl;
    28053039}
     
    28093043        }
    28103044        ///////////////////////
    2811         case XRAM_RSP_TRT_COPY:         // Takes the lock on TRT
    2812                                     // Copy the TRT entry in a local buffer
    2813                                     // and select a victim cache line
    2814         {
    2815             if ( (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP) )
    2816             {
    2817                 // copy the TRT entry in the r_xram_rsp_trt_buf local buffer
    2818                 size_t  index = r_xram_rsp_trt_index.read();
    2819                 TransactionTabEntry    trt_entry(m_transaction_tab.read(index)); 
    2820                 r_xram_rsp_trt_buf.copy(trt_entry);  // TRT entry local buffer
    2821 
     3045        case XRAM_RSP_TRT_COPY:
     3046        // Select a victim cache line
     3047        {
     3048            if ( (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP) )
     3049            {
    28223050                // selects & extracts a victim line from cache
    28233051                size_t way = 0;
    2824                 size_t set = m_y[(vci_addr_t)(trt_entry.nline * m_words * 4)];
     3052                size_t set = m_y[(vci_addr_t)(r_xram_rsp_trt_buf.nline * m_words * 4)];
     3053
    28253054                DirectoryEntry victim(m_cache_directory.select(set, way));
    28263055
     
    28283057
    28293058                // copy the victim line in a local buffer
    2830                 for (size_t i=0 ; i<m_words ; i++)
    2831                     r_xram_rsp_victim_data[i] = m_cache_data[way][set][i];
     3059                for (size_t i=0 ; i<m_words ; i++)
     3060                  r_xram_rsp_victim_data[i] = m_cache_data[way][set][i];
     3061
    28323062                r_xram_rsp_victim_copy      = victim.owner.srcid;
    28333063#if L1_MULTI_CACHE
     
    28443074                r_xram_rsp_victim_dirty     = victim.dirty;
    28453075
    2846                 if(!trt_entry.rerror)   r_xram_rsp_fsm = XRAM_RSP_INVAL_LOCK;
    2847                 else                            r_xram_rsp_fsm = XRAM_RSP_ERROR_ERASE;     
     3076                if(!r_xram_rsp_trt_buf.rerror)
     3077                {
     3078                  r_xram_rsp_fsm = XRAM_RSP_INVAL_LOCK;
     3079                }
     3080                else
     3081                {
     3082                  r_xram_rsp_fsm = XRAM_RSP_ERROR_ERASE;
     3083                }
    28483084
    28493085#if DEBUG_MEMC_XRAM_RSP
     
    28513087{
    28523088    std::cout << "  <MEMC " << name() << ".XRAM_RSP_TRT_COPY> Select a slot: "
    2853               << " way = " << std::dec << way 
    2854               << " / set = " << set 
     3089              << " way = " << std::dec << way
     3090              << " / set = " << set
    28553091              << " / inval_required = " << inval << std::endl;
    28563092}
    28573093#endif
    28583094            }
     3095            else
     3096            {
     3097                std::cout << "VCI_MEM_CACHE ERROR "     << name()
     3098                          << " XRAM_RSP_TRT_COPY state" << std::endl
     3099                          << "bad TRT allocation"       << std::endl;
     3100
     3101                exit(0);
     3102            }
    28593103            break;
    28603104        }
    28613105        /////////////////////////
    2862         case XRAM_RSP_INVAL_LOCK:       // check a possible pending inval
    2863         {
    2864             if ( r_alloc_upt_fsm == ALLOC_UPT_XRAM_RSP ) 
     3106        case XRAM_RSP_INVAL_LOCK: // check a possible pending inval
     3107        {
     3108            if ( r_alloc_upt_fsm == ALLOC_UPT_XRAM_RSP )
    28653109            {
    28663110                size_t index;
     
    28793123
    28803124                }
    2881                     else if (m_update_tab.is_full() && r_xram_rsp_victim_inval.read())
     3125              else if (m_update_tab.is_full() && r_xram_rsp_victim_inval.read())
    28823126                {
    2883                         r_xram_rsp_fsm = XRAM_RSP_INVAL_WAIT;
     3127                  r_xram_rsp_fsm = XRAM_RSP_INVAL_WAIT;
    28843128
    28853129#if DEBUG_MEMC_XRAM_RSP
     
    28913135}
    28923136#endif
    2893                     }
    2894                 else 
     3137              }
     3138                else
    28953139                {
    28963140                    r_xram_rsp_fsm = XRAM_RSP_DIR_UPDT;
     
    29073151        }
    29083152        /////////////////////////
    2909         case XRAM_RSP_INVAL_WAIT:       // returns to DIR_LOCK to retry
     3153        case XRAM_RSP_INVAL_WAIT: // returns to DIR_LOCK to retry
    29103154        {
    29113155            r_xram_rsp_fsm = XRAM_RSP_DIR_LOCK;
     
    29133157        }
    29143158        ///////////////////////
    2915         case XRAM_RSP_DIR_UPDT:         // updates the cache (both data & directory)
    2916                                         // and possibly set an inval request in UPT 
     3159        case XRAM_RSP_DIR_UPDT:   // updates the cache (both data & directory)
     3160                                        // and possibly set an inval request in UPT
    29173161        {
    29183162            // signals generation
    2919             bool inst_read = (r_xram_rsp_trt_buf.trdid & 0x2) && r_xram_rsp_trt_buf.proc_read; 
     3163            bool inst_read = (r_xram_rsp_trt_buf.trdid & 0x2) && r_xram_rsp_trt_buf.proc_read;
    29203164            bool cached_read = (r_xram_rsp_trt_buf.trdid & 0x1) && r_xram_rsp_trt_buf.proc_read;
    29213165            // update data
    29223166            size_t set   = r_xram_rsp_victim_set.read();
    29233167            size_t way   = r_xram_rsp_victim_way.read();
    2924             for(size_t i=0; i<m_words ; i++) 
     3168            for(size_t i=0; i<m_words ; i++)
    29253169            {
    29263170                m_cache_data[way][set][i] = r_xram_rsp_trt_buf.wdata[i];
    29273171
    2928                 if ( m_monitor_ok ) 
     3172                if ( m_monitor_ok )
    29293173                {
    2930                     vci_addr_t address = r_xram_rsp_trt_buf.nline<<6 | i<<2; 
     3174                    vci_addr_t address = r_xram_rsp_trt_buf.nline<<6 | i<<2;
    29313175                    check_monitor("XRAM_RSP_DIR_UPDT", address, r_xram_rsp_trt_buf.wdata[i]);
    29323176                }
    29333177            }
    2934             // compute dirty 
     3178            // compute dirty
    29353179            bool dirty = false;
    29363180            for(size_t i=0; i<m_words;i++) dirty = dirty || (r_xram_rsp_trt_buf.wdata_be[i] != 0);
    29373181            // update directory
    29383182            DirectoryEntry entry;
    2939             entry.valid   = true;
     3183            entry.valid   = true;
    29403184            entry.is_cnt  = false;
    2941             entry.lock    = false;
    2942             entry.dirty   = dirty;
    2943             entry.tag     = r_xram_rsp_trt_buf.nline / m_sets;
     3185            entry.lock    = false;
     3186            entry.dirty   = dirty;
     3187            entry.tag   = r_xram_rsp_trt_buf.nline / m_sets;
    29443188            entry.ptr     = 0;
    2945             if(cached_read) 
     3189            if(cached_read)
    29463190            {
    29473191                entry.owner.srcid   = r_xram_rsp_trt_buf.srcid;
     
    29513195                entry.owner.inst    = inst_read;
    29523196                entry.count         = 1;
    2953             } 
    2954             else 
     3197            }
     3198            else
    29553199            {
    29563200                entry.owner.srcid    = 0;
     
    29653209            if (r_xram_rsp_victim_inval.read())
    29663210            {
    2967                 bool   brdcast          = r_xram_rsp_victim_is_cnt.read();
    2968                 size_t index            = 0;
    2969                 size_t count_copies     = r_xram_rsp_victim_count.read();
    2970 
    2971                 bool   wok = m_update_tab.set(  false,          // it's an inval transaction
    2972                                                 brdcast,        // set brdcast bit
    2973                                                 false,          // it does not need a response
    2974                                                 0,              // srcid
    2975                                                 0,              // trdid
    2976                                                 0,              // pktid
    2977                                                 r_xram_rsp_victim_nline.read(),
    2978                                                 count_copies,
    2979                                                 index);
     3211                bool   brdcast    = r_xram_rsp_victim_is_cnt.read();
     3212                size_t index    = 0;
     3213                size_t count_copies   = r_xram_rsp_victim_count.read();
     3214
     3215                bool   wok = m_update_tab.set(  false,    // it's an inval transaction
     3216                        brdcast,  // set brdcast bit
     3217                        false,    // it does not need a response
     3218                        0,    // srcid
     3219                        0,    // trdid
     3220                        0,    // pktid
     3221                        r_xram_rsp_victim_nline.read(),
     3222                        count_copies,
     3223                        index);
    29803224                r_xram_rsp_upt_index = index;
    29813225
    2982                 if (!wok) 
     3226                if (!wok)
    29833227                {
    29843228                    std::cout << "VCI_MEM_CACHE ERROR " << name() << " XRAM_RSP_HEAP_LAST state" << std::endl;
     
    29923236{
    29933237    std::cout << "  <MEMC " << name() << ".XRAM_RSP_DIR_UPDT> Directory update: "
    2994               << " way = " << std::dec << way 
    2995               << " / set = " << set 
     3238              << " way = " << std::dec << way
     3239              << " / set = " << set
    29963240              << " / count = " << entry.count
    29973241              << " / is_cnt = " << entry.is_cnt << std::endl;
     
    30043248
    30053249            // If the victim is not dirty, we don't need another XRAM  put transaction,
    3006             // and we canwe erase the TRT entry 
     3250            // and we canwe erase the TRT entry
    30073251            if (!r_xram_rsp_victim_dirty.read())  m_transaction_tab.erase(r_xram_rsp_trt_index.read());
    30083252
     
    30173261        case XRAM_RSP_TRT_DIRTY:  // set the TRT entry (write to XRAM) if the victim is dirty
    30183262        {
    3019             if ( r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP ) 
     3263            if ( r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP )
    30203264            {
    30213265                m_transaction_tab.set( r_xram_rsp_trt_index.read(),
    3022                                        false,                           // write to XRAM
     3266                                       false,       // write to XRAM
    30233267                                       r_xram_rsp_victim_nline.read(),  // line index
    30243268                                       0,
     
    30353279{
    30363280    std::cout << "  <MEMC " << name() << ".XRAM_RSP_TRT_DIRTY> Set TRT entry for the put transaction:"
    3037               << " dirty victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
     3281        << " dirty victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
    30383282}
    30393283#endif
     
    30473291        case XRAM_RSP_DIR_RSP:     // Request a response to TGT_RSP FSM
    30483292        {
    3049             if ( !r_xram_rsp_to_tgt_rsp_req.read() ) 
     3293            if ( !r_xram_rsp_to_tgt_rsp_req.read() )
    30503294            {
    30513295                r_xram_rsp_to_tgt_rsp_srcid = r_xram_rsp_trt_buf.srcid;
    30523296                r_xram_rsp_to_tgt_rsp_trdid = r_xram_rsp_trt_buf.trdid;
    30533297                r_xram_rsp_to_tgt_rsp_pktid = r_xram_rsp_trt_buf.pktid;
    3054                 for (size_t i=0; i < m_words; i++) r_xram_rsp_to_tgt_rsp_data[i] = r_xram_rsp_trt_buf.wdata[i]; 
     3298                for (size_t i=0; i < m_words; i++) r_xram_rsp_to_tgt_rsp_data[i] = r_xram_rsp_trt_buf.wdata[i];
    30553299                r_xram_rsp_to_tgt_rsp_word   = r_xram_rsp_trt_buf.word_index;
    30563300                r_xram_rsp_to_tgt_rsp_length = r_xram_rsp_trt_buf.read_length;
     
    30593303
    30603304                if      ( r_xram_rsp_victim_inval ) r_xram_rsp_fsm = XRAM_RSP_INVAL;
    3061                 else if ( r_xram_rsp_victim_dirty ) r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY; 
     3305                else if ( r_xram_rsp_victim_dirty ) r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY;
    30623306                else                                r_xram_rsp_fsm = XRAM_RSP_IDLE;
    30633307
     
    30663310if( m_debug_xram_rsp_fsm )
    30673311{
    3068     std::cout << "  <MEMC " << name() << ".XRAM_RSP_DIR_RSP> Request the TGT_RSP FSM to return data:" 
     3312    std::cout << "  <MEMC " << name() << ".XRAM_RSP_DIR_RSP> Request the TGT_RSP FSM to return data:"
    30693313              << " rsrcid = " << std::dec << r_xram_rsp_trt_buf.srcid
    30703314              << " / address = " << std::hex << r_xram_rsp_trt_buf.nline*m_words*4
     
    30763320        }
    30773321        ////////////////////
    3078         case XRAM_RSP_INVAL:    // send invalidate request to INIT_CMD FSM
    3079         {
    3080             if(   !r_xram_rsp_to_init_cmd_multi_req.read() && 
    3081                   !r_xram_rsp_to_init_cmd_brdcast_req.read() ) 
    3082             {         
     3322        case XRAM_RSP_INVAL:  // send invalidate request to INIT_CMD FSM
     3323        {
     3324            if(   !r_xram_rsp_to_init_cmd_multi_req.read() &&
     3325                  !r_xram_rsp_to_init_cmd_brdcast_req.read() )
     3326            {
    30833327                bool multi_req = !r_xram_rsp_victim_is_cnt.read();
    30843328                bool last_multi_req  = multi_req && (r_xram_rsp_victim_count.read() == 1);
    30853329                bool not_last_multi_req = multi_req && (r_xram_rsp_victim_count.read() != 1);
    30863330
    3087                 r_xram_rsp_to_init_cmd_multi_req    = last_multi_req; 
     3331                r_xram_rsp_to_init_cmd_multi_req    = last_multi_req;
    30883332                r_xram_rsp_to_init_cmd_brdcast_req  = r_xram_rsp_victim_is_cnt.read();
    30893333                r_xram_rsp_to_init_cmd_nline        = r_xram_rsp_victim_nline.read();
     
    30983342
    30993343                if ( r_xram_rsp_victim_dirty )  r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY;
    3100                 else if (not_last_multi_req)    r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
     3344                else if (not_last_multi_req)    r_xram_rsp_fsm = XRAM_RSP_HEAP_REQ;
    31013345                else                            r_xram_rsp_fsm = XRAM_RSP_IDLE;
    31023346
     
    31043348if( m_debug_xram_rsp_fsm )
    31053349{
    3106     std::cout << "  <MEMC " << name() << ".XRAM_RSP_INVAL> Send an inval request to INIT_CMD FSM:" 
     3350    std::cout << "  <MEMC " << name() << ".XRAM_RSP_INVAL> Send an inval request to INIT_CMD FSM:"
    31073351              << " victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
    31083352}
     
    31123356        }
    31133357        //////////////////////////
    3114         case XRAM_RSP_WRITE_DIRTY:      // send a write request to IXR_CMD FSM
    3115         {
    3116             if ( !r_xram_rsp_to_ixr_cmd_req.read() ) 
     3358        case XRAM_RSP_WRITE_DIRTY:  // send a write request to IXR_CMD FSM
     3359        {
     3360            if ( !r_xram_rsp_to_ixr_cmd_req.read() )
    31173361            {
    31183362                r_xram_rsp_to_ixr_cmd_req = true;
     
    31243368                bool multi_req = !r_xram_rsp_victim_is_cnt.read() && r_xram_rsp_victim_inval.read();
    31253369                bool not_last_multi_req = multi_req && (r_xram_rsp_victim_count.read() != 1);
    3126                 if ( not_last_multi_req )   r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
     3370                if ( not_last_multi_req )   r_xram_rsp_fsm = XRAM_RSP_HEAP_REQ;
    31273371                else                        r_xram_rsp_fsm = XRAM_RSP_IDLE;
    31283372
     
    31303374if( m_debug_xram_rsp_fsm )
    31313375{
    3132     std::cout << "  <MEMC " << name() << ".XRAM_RSP_WRITE_DIRTY> Send the put request to IXR_CMD FSM:" 
     3376    std::cout << "  <MEMC " << name() << ".XRAM_RSP_WRITE_DIRTY> Send the put request to IXR_CMD FSM:"
    31333377              << " victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
    31343378}
     
    31373381            break;
    31383382        }
     3383
    31393384        /////////////////////////
    3140         case XRAM_RSP_HEAP_ERASE:       // erase the list of copies and sent invalidations
    3141         {
    3142             if( r_alloc_heap_fsm.read() == ALLOC_HEAP_XRAM_RSP )
     3385        case XRAM_RSP_HEAP_REQ:
     3386        // Get the lock to the HEAP directory
     3387        {
     3388          if( r_alloc_heap_fsm.read() == ALLOC_HEAP_XRAM_RSP )
     3389          {
     3390            r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
     3391          }
     3392
     3393#if DEBUG_MEMC_XRAM_RSP
     3394          if( m_debug_xram_rsp_fsm )
     3395          {
     3396            std::cout
     3397              << "  <MEMC " << name() << ".XRAM_RSP_HEAP_REQ> Requesting HEAP lock "
     3398              << std::endl;
     3399          }
     3400#endif
     3401          break;
     3402        }
     3403
     3404        /////////////////////////
     3405        case XRAM_RSP_HEAP_ERASE: // erase the list of copies and sent invalidations
     3406        {
     3407            if( r_alloc_heap_fsm.read() == ALLOC_HEAP_XRAM_RSP )
    31433408            {
    31443409                HeapEntry entry = m_heap.read(r_xram_rsp_next_ptr.read());
     
    31573422                        r_xram_rsp_to_init_cmd_multi_req = true;
    31583423                        r_xram_rsp_fsm = XRAM_RSP_HEAP_LAST;
    3159                     } 
    3160                     else 
     3424                    }
     3425                    else
    31613426                    {
    31623427                        r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
    31633428                    }
    3164                 } 
    3165                 else 
     3429                }
     3430                else
    31663431                {
    31673432                    r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
     
    31713436if( m_debug_xram_rsp_fsm )
    31723437{
    3173     std::cout << "  <MEMC " << name() << ".XRAM_RSP_HEAP_ERASE> Erase the list of copies:" 
     3438    std::cout << "  <MEMC " << name() << ".XRAM_RSP_HEAP_ERASE> Erase the list of copies:"
    31743439              << " srcid = " << std::dec << entry.owner.srcid
    31753440              << " / inst = " << std::dec << entry.owner.inst << std::endl;
     
    31803445        }
    31813446        /////////////////////////
    3182         case XRAM_RSP_HEAP_LAST:        // last member of the list
     3447        case XRAM_RSP_HEAP_LAST:  // last member of the list
    31833448        {
    31843449            if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_XRAM_RSP )
     
    32003465                last_entry.next     = r_xram_rsp_next_ptr.read();
    32013466                m_heap.unset_full();
    3202             } 
    3203             else 
     3467            }
     3468            else
    32043469            {
    32053470                last_entry.next     = free_pointer;
     
    32203485        }
    32213486        // ///////////////////////
    3222         case XRAM_RSP_ERROR_ERASE:      // erase TRT entry in case of error
     3487        case XRAM_RSP_ERROR_ERASE:  // erase TRT entry in case of error
    32233488        {
    32243489            m_transaction_tab.erase(r_xram_rsp_trt_index.read());
     
    32373502        }
    32383503        ////////////////////////
    3239         case XRAM_RSP_ERROR_RSP:     // Request an error response to TGT_RSP FSM 
    3240         {
    3241             if ( !r_xram_rsp_to_tgt_rsp_req.read() ) 
     3504        case XRAM_RSP_ERROR_RSP:     // Request an error response to TGT_RSP FSM
     3505        {
     3506            if ( !r_xram_rsp_to_tgt_rsp_req.read() )
    32423507            {
    32433508                r_xram_rsp_to_tgt_rsp_srcid  = r_xram_rsp_trt_buf.srcid;
     
    32653530
    32663531    ////////////////////////////////////////////////////////////////////////////////////
    3267     //          CLEANUP FSM
     3532    //    CLEANUP FSM
    32683533    ////////////////////////////////////////////////////////////////////////////////////
    32693534    // The CLEANUP FSM handles the cleanup request from L1 caches.
     
    32713536    ////////////////////////////////////////////////////////////////////////////////////
    32723537
    3273 
    3274     switch ( r_cleanup_fsm.read() )
     3538    switch ( r_cleanup_fsm.read() )
    32753539    {
    3276         //////////////////
    3277         case CLEANUP_IDLE:
    3278         {
    3279             if ( p_vci_tgt_cleanup.cmdval.read() )
    3280             {
    3281                 if (p_vci_tgt_cleanup.srcid.read() >= m_initiators )
    3282                 {
    3283                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    3284                               << " CLEANUP_IDLE state" << std::endl;
    3285                     std::cout << "illegal srcid for  cleanup request" << std::endl;
    3286                     exit(0);
    3287                 }
    3288 
    3289                 bool reached = false;
    3290                 for ( size_t index = 0 ; index < m_ncseg && !reached ; index++ )
    3291                 {
    3292                     if ( m_cseg[index]->contains((addr_t)(p_vci_tgt_cleanup.address.read())) )
    3293                         reached = true;
    3294                 }
    3295                 // only write request to a mapped address that are not broadcast are handled
    3296                 if ( (p_vci_tgt_cleanup.cmd.read() == vci_param::CMD_WRITE) &&
    3297                      ((p_vci_tgt_cleanup.address.read() & 0x3) == 0) && reached)
    3298                 {
    3299                     addr_t line =(((addr_t) p_vci_tgt_cleanup.be.read() << (vci_param::B*8))) |
    3300                                  (((addr_t) p_vci_tgt_cleanup.wdata.read()));
    3301 
    3302                     r_cleanup_nline = line;
    3303                     r_cleanup_srcid = p_vci_tgt_cleanup.srcid.read();
    3304                     r_cleanup_trdid = p_vci_tgt_cleanup.trdid.read();
    3305                     r_cleanup_pktid = p_vci_tgt_cleanup.pktid.read();
    3306                     r_cleanup_fsm   = CLEANUP_DIR_LOCK;
     3540      //////////////////
     3541      case CLEANUP_IDLE:
     3542      {
     3543        if ( p_vci_tgt_cleanup.cmdval.read() )
     3544        {
     3545          if (p_vci_tgt_cleanup.srcid.read() >= m_initiators )
     3546          {
     3547            std::cout << "VCI_MEM_CACHE ERROR " << name()
     3548              << " CLEANUP_IDLE state" << std::endl;
     3549            std::cout << "illegal srcid for  cleanup request" << std::endl;
     3550            exit(0);
     3551          }
     3552
     3553          bool reached = false;
     3554          for ( size_t index = 0 ; index < m_ncseg && !reached ; index++ )
     3555          {
     3556            if ( m_cseg[index]->contains((addr_t)(p_vci_tgt_cleanup.address.read())) )
     3557              reached = true;
     3558          }
     3559          // only write request to a mapped address that are not broadcast are handled
     3560          if (( p_vci_tgt_cleanup.cmd.read() == vci_param::CMD_WRITE ) &&
     3561              (( p_vci_tgt_cleanup.address.read() & 0x3 ) == 0 ) && reached )
     3562          {
     3563            addr_t line =(((addr_t) p_vci_tgt_cleanup.be.read() << (vci_param::B*8))) |
     3564              (((addr_t) p_vci_tgt_cleanup.wdata.read()));
     3565
     3566            r_cleanup_nline = line;
     3567            r_cleanup_srcid = p_vci_tgt_cleanup.srcid.read();
     3568            r_cleanup_trdid = p_vci_tgt_cleanup.trdid.read();
     3569            r_cleanup_pktid = p_vci_tgt_cleanup.pktid.read();
     3570            r_cleanup_fsm   = CLEANUP_DIR_REQ;
     3571
     3572  #if DEBUG_MEMC_CLEANUP
     3573            if( m_debug_cleanup_fsm )
     3574            {
     3575              std::cout << "  <MEMC " << name() << ".CLEANUP_IDLE> Cleanup request:" << std::hex
     3576                << " line addr = " << line * m_words * 4
     3577                << " / owner_id = " << p_vci_tgt_cleanup.srcid.read()
     3578                << " / owner_ins = " << (p_vci_tgt_cleanup.trdid.read()&0x1)
     3579                << std::endl;
     3580            }
     3581  #endif
     3582            m_cpt_cleanup++;
     3583          }
     3584        }
     3585        break;
     3586      }
     3587
     3588      //////////////////////
     3589      case CLEANUP_DIR_REQ:
     3590      // Get the lock to the directory
     3591      {
     3592        if ( r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP )
     3593        {
     3594          r_cleanup_fsm = CLEANUP_DIR_LOCK;
     3595        }
    33073596
    33083597#if DEBUG_MEMC_CLEANUP
    3309 if( m_debug_cleanup_fsm )
    3310 {
    3311     std::cout << "  <MEMC " << name() << ".CLEANUP_IDLE> Cleanup request:" << std::hex
    3312               << " line addr = " << line * m_words * 4
    3313               << " / owner_id = " << p_vci_tgt_cleanup.srcid.read()
    3314               << " / owner_ins = " << (p_vci_tgt_cleanup.trdid.read()&0x1)
    3315               << std::endl;
    3316 }
    3317 #endif
    3318                     m_cpt_cleanup++;
    3319                 }
    3320             }
    3321             break;
    3322         }
    3323         //////////////////////
    3324         case CLEANUP_DIR_LOCK:  // test directory status
    3325         {
    3326             if ( r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP )
    3327             {
    3328                 // Read the directory
    3329                 size_t way = 0;
    3330                     addr_t cleanup_address = r_cleanup_nline.read() * m_words * 4;
    3331                 DirectoryEntry entry   = m_cache_directory.read(cleanup_address , way);
    3332                 r_cleanup_is_cnt       = entry.is_cnt;
    3333                 r_cleanup_dirty        = entry.dirty;
    3334                 r_cleanup_tag          = entry.tag;
    3335                 r_cleanup_lock         = entry.lock;
    3336                 r_cleanup_way          = way;
    3337                 r_cleanup_copy         = entry.owner.srcid;
     3598        if( m_debug_cleanup_fsm )
     3599        {
     3600          std::cout
     3601            << "  <MEMC " << name() << ".CLEANUP_DIR_REQ> Requesting DIR lock "
     3602            << std::endl;
     3603        }
     3604#endif
     3605        break;
     3606      }
     3607
     3608      //////////////////////
     3609      case CLEANUP_DIR_LOCK:  // test directory status
     3610      {
     3611        if ( r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP )
     3612        {
     3613          // Read the directory
     3614          size_t way = 0;
     3615          addr_t cleanup_address = r_cleanup_nline.read() * m_words * 4;
     3616          DirectoryEntry entry   = m_cache_directory.read(cleanup_address , way);
     3617          r_cleanup_is_cnt       = entry.is_cnt;
     3618          r_cleanup_dirty        = entry.dirty;
     3619          r_cleanup_tag          = entry.tag;
     3620          r_cleanup_lock         = entry.lock;
     3621          r_cleanup_way          = way;
     3622          r_cleanup_copy         = entry.owner.srcid;
    33383623#if L1_MULTI_CACHE
    3339                 r_cleanup_copy_cache= entry.owner.cache_id;
    3340 #endif
    3341                 r_cleanup_copy_inst    = entry.owner.inst;
    3342                 r_cleanup_count        = entry.count;
    3343                 r_cleanup_ptr          = entry.ptr;
    3344 
    3345                 if( entry.valid) //  hit : the copy must be cleared 
    3346                 {
    3347                     if ( (entry.count==1) || (entry.is_cnt) )  // no access to the heap
    3348                     {
    3349                         r_cleanup_fsm = CLEANUP_DIR_WRITE;
    3350                     }
    3351                     else                                        // access to the heap
    3352                     {
    3353                         r_cleanup_fsm = CLEANUP_HEAP_LOCK;
    3354                     }
    3355                 }
    3356                 else            // miss : we must check the update table
    3357                 {
    3358                     r_cleanup_fsm = CLEANUP_UPT_LOCK;
    3359                 }
     3624          r_cleanup_copy_cache   = entry.owner.cache_id;
     3625#endif
     3626          r_cleanup_copy_inst    = entry.owner.inst;
     3627          r_cleanup_count        = entry.count;
     3628          r_cleanup_ptr          = entry.ptr;
     3629
     3630          if( entry.valid) //  hit : the copy must be cleared
     3631          {
     3632            if ( (entry.count==1) || (entry.is_cnt) )  // no access to the heap
     3633            {
     3634              r_cleanup_fsm = CLEANUP_DIR_WRITE;
     3635            }
     3636            else          // access to the heap
     3637            {
     3638              r_cleanup_fsm = CLEANUP_HEAP_REQ;
     3639            }
     3640          }
     3641          else    // miss : we must check the update table
     3642          {
     3643            r_cleanup_fsm = CLEANUP_UPT_LOCK;
     3644          }
    33603645
    33613646#if DEBUG_MEMC_CLEANUP
    3362 if( m_debug_cleanup_fsm )
    3363 {
    3364     std::cout << "  <MEMC " << name() << ".CLEANUP_DIR_LOCK> Test directory status: " << std::hex
     3647          if( m_debug_cleanup_fsm )
     3648          {
     3649            std::cout
     3650              << "  <MEMC " << name()
     3651              << ".CLEANUP_DIR_LOCK> Test directory status: " << std::hex
    33653652              << " line = " << r_cleanup_nline.read() * m_words * 4
    33663653              << " / hit = " << entry.valid
    33673654              << " / dir_id = " << entry.owner.srcid
    33683655              << " / dir_ins = " << entry.owner.inst
    3369               << " / search_id = " << r_cleanup_srcid.read() 
     3656              << " / search_id = " << r_cleanup_srcid.read()
    33703657              << " / search_ins = " << (r_cleanup_trdid.read()&0x1)
    33713658              << " / count = " << entry.count
    33723659              << " / is_cnt = " << entry.is_cnt << std::endl;
    3373 }
    3374 #endif
    3375             }
    3376             break;
    3377         }
    3378         ///////////////////////
    3379         case CLEANUP_DIR_WRITE:  //  update the directory entry without heap access
    3380         {
    3381             if ( r_alloc_dir_fsm.read() != ALLOC_DIR_CLEANUP )
    3382             {
    3383                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    3384                           << " CLEANUP_DIR_WRITE state"
    3385                           << " bad DIR allocation" << std::endl;
    3386                 exit(0);
    3387             }
    3388 
    3389             size_t way         = r_cleanup_way.read();
    3390             size_t set         = m_y[(vci_addr_t)(r_cleanup_nline.read()*m_words*4)];
    3391             bool cleanup_inst  = r_cleanup_trdid.read() & 0x1;
    3392             bool match_srcid   = ((r_cleanup_copy.read() == r_cleanup_srcid.read())
     3660          }
     3661#endif
     3662        }
     3663        else
     3664        {
     3665          std::cout << "VCI_MEM_CACHE ERROR " << name()
     3666            << " CLEANUP_DIR_LOCK state"
     3667            << " bad DIR allocation" << std::endl;
     3668
     3669          exit(0);
     3670        }
     3671        break;
     3672      }
     3673
     3674      ///////////////////////
     3675      case CLEANUP_DIR_WRITE:
     3676      // Update the directory entry without heap access
     3677      {
     3678        if ( r_alloc_dir_fsm.read() != ALLOC_DIR_CLEANUP )
     3679        {
     3680          std::cout << "VCI_MEM_CACHE ERROR " << name()
     3681            << " CLEANUP_DIR_WRITE state"
     3682            << " bad DIR allocation" << std::endl;
     3683          exit(0);
     3684        }
     3685
     3686        size_t way         = r_cleanup_way.read();
     3687        size_t set         = m_y[(vci_addr_t)(r_cleanup_nline.read()*m_words*4)];
     3688        bool cleanup_inst  = r_cleanup_trdid.read() & 0x1;
     3689        bool match_srcid   = ((r_cleanup_copy.read() == r_cleanup_srcid.read())
    33933690#if L1_MULTI_CACHE
    3394                                 and (r_cleanup_copy_cache.read() == r_cleanup_pktid.read())
    3395 #endif
    3396                                 );
    3397             bool match_inst    = (r_cleanup_copy_inst.read()  == cleanup_inst);
    3398             bool match         = match_srcid && match_inst;
    3399 
    3400             // update the cache directory (for the copies)
    3401             DirectoryEntry entry;
    3402             entry.valid   = true;
    3403             entry.is_cnt  = r_cleanup_is_cnt.read();
    3404             entry.dirty   = r_cleanup_dirty.read();
    3405             entry.tag     = r_cleanup_tag.read();
    3406             entry.lock    = r_cleanup_lock.read();
    3407             entry.ptr     = r_cleanup_ptr.read();
    3408 
    3409             if ( r_cleanup_is_cnt.read() )      // counter mode
    3410             {
    3411                 entry.count  = r_cleanup_count.read() -1;
    3412                 entry.owner.srcid   = 0;
     3691            and (r_cleanup_copy_cache.read() == r_cleanup_pktid.read())
     3692#endif
     3693            );
     3694        bool match_inst    = (r_cleanup_copy_inst.read()  == cleanup_inst);
     3695        bool match         = match_srcid && match_inst;
     3696
     3697        // update the cache directory (for the copies)
     3698        DirectoryEntry entry;
     3699        entry.valid   = true;
     3700        entry.is_cnt  = r_cleanup_is_cnt.read();
     3701        entry.dirty   = r_cleanup_dirty.read();
     3702        entry.tag     = r_cleanup_tag.read();
     3703        entry.lock    = r_cleanup_lock.read();
     3704        entry.ptr     = r_cleanup_ptr.read();
     3705
     3706        if ( r_cleanup_is_cnt.read() )      // counter mode
     3707        {
     3708          entry.count  = r_cleanup_count.read() -1;
     3709          entry.owner.srcid   = 0;
    34133710#if L1_MULTI_CACHE
    3414                 entry.owner.cache_id= 0;
    3415 #endif
    3416                 entry.owner.inst    = 0;
    3417                 // response to the cache
    3418                 r_cleanup_fsm = CLEANUP_RSP;
    3419             }
    3420             else                                            // linked_list mode
    3421             {                       
    3422                 if ( match )  // hit
    3423                 {
    3424                     entry.count         = 0; // no more copy
    3425                     entry.owner.srcid   = 0;
     3711          entry.owner.cache_id= 0;
     3712#endif
     3713          entry.owner.inst    = 0;
     3714          // response to the cache
     3715          r_cleanup_fsm = CLEANUP_RSP;
     3716        }
     3717        else                          // linked_list mode
     3718        {
     3719          if ( match )  // hit
     3720          {
     3721            entry.count         = 0; // no more copy
     3722            entry.owner.srcid   = 0;
    34263723#if L1_MULTI_CACHE
    3427                     entry.owner.cache_id=0;
    3428 #endif
    3429                     entry.owner.inst    = 0;
    3430                     r_cleanup_fsm       = CLEANUP_RSP;
    3431                 }
    3432                 else         // miss
    3433                 {
    3434                     entry.count          = r_cleanup_count.read();
    3435                     entry.owner.srcid    = r_cleanup_copy.read();
     3724            entry.owner.cache_id=0;
     3725#endif
     3726            entry.owner.inst    = 0;
     3727            r_cleanup_fsm       = CLEANUP_RSP;
     3728          }
     3729          else         // miss
     3730          {
     3731            entry.count          = r_cleanup_count.read();
     3732            entry.owner.srcid    = r_cleanup_copy.read();
    34363733#if L1_MULTI_CACHE
    3437                     entry.owner.cache_id = r_cleanup_copy_cache.read();
    3438 #endif
    3439                     entry.owner.inst     = r_cleanup_copy_inst.read();
    3440                     r_cleanup_fsm        = CLEANUP_UPT_LOCK;
    3441                 }
    3442             }
    3443             m_cache_directory.write(set, way, entry); 
     3734            entry.owner.cache_id = r_cleanup_copy_cache.read();
     3735#endif
     3736            entry.owner.inst     = r_cleanup_copy_inst.read();
     3737            r_cleanup_fsm        = CLEANUP_UPT_LOCK;
     3738          }
     3739        }
     3740        m_cache_directory.write(set, way, entry);
    34443741
    34453742#if DEBUG_MEMC_CLEANUP
    3446 if( m_debug_cleanup_fsm )
    3447 {
    3448     std::cout << "  <MEMC " << name() << ".CLEANUP_DIR_WRITE> Update directory:" << std::hex
    3449               << " line = " << r_cleanup_nline.read() * m_words * 4
    3450               << " / dir_id = " << entry.owner.srcid
    3451               << " / dir_ins = " << entry.owner.inst
    3452               << " / count = " << entry.count
    3453               << " / is_cnt = " << entry.is_cnt << std::endl;
    3454 }
    3455 #endif
    3456 
    3457             break;
    3458         }
    3459         ///////////////////////
    3460         case CLEANUP_HEAP_LOCK:  // two cases are handled in this state:
    3461                                  // - the matching copy is directly in the directory
    3462                                  // - the matching copy is the first copy in the heap
    3463         {
    3464             if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP )
    3465             {
    3466                 size_t way              = r_cleanup_way.read();
    3467                 size_t set              = m_y[(vci_addr_t)(r_cleanup_nline.read()*m_words*4)];
    3468                 HeapEntry heap_entry    = m_heap.read(r_cleanup_ptr.read());
    3469                 bool last               = (heap_entry.next == r_cleanup_ptr.read());
    3470                 bool cleanup_inst       = r_cleanup_trdid.read() & 0x1;
    3471 
    3472                 // match_dir computation
    3473                 bool match_dir_srcid    = (r_cleanup_copy.read() == r_cleanup_srcid.read());
    3474                 bool match_dir_inst     = (r_cleanup_copy_inst.read()  == cleanup_inst);
    3475                 bool match_dir          = match_dir_srcid and match_dir_inst;
     3743        if( m_debug_cleanup_fsm )
     3744        {
     3745          std::cout
     3746            << "  <MEMC " << name()
     3747            << ".CLEANUP_DIR_WRITE> Update directory:" << std::hex
     3748            << " line = " << r_cleanup_nline.read() * m_words * 4
     3749            << " / dir_id = " << entry.owner.srcid
     3750            << " / dir_ins = " << entry.owner.inst
     3751            << " / count = " << entry.count
     3752            << " / is_cnt = " << entry.is_cnt << std::endl;
     3753        }
     3754#endif
     3755
     3756        break;
     3757      }
     3758     
     3759      ///////////////////////
     3760      case CLEANUP_HEAP_REQ:
     3761      // Get the lock to the HEAP directory
     3762      {
     3763        if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP )
     3764        {
     3765          r_cleanup_fsm = CLEANUP_HEAP_LOCK;
     3766        }
     3767
     3768#if DEBUG_MEMC_CLEANUP
     3769        if( m_debug_cleanup_fsm )
     3770        {
     3771          std::cout
     3772            << "  <MEMC " << name() << ".CLEANUP_HEAP_REQ> Requesting HEAP lock "
     3773            << std::endl;
     3774        }
     3775#endif
     3776        break;
     3777      }
     3778
     3779      ///////////////////////
     3780      case CLEANUP_HEAP_LOCK:
     3781      // two cases are handled in this state:
     3782      // - the matching copy is directly in the directory
     3783      // - the matching copy is the first copy in the heap
     3784      {
     3785        if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP )
     3786        {
     3787          size_t way              = r_cleanup_way.read();
     3788          size_t set              = m_y[(vci_addr_t)(r_cleanup_nline.read()*m_words*4)];
     3789          HeapEntry heap_entry    = m_heap.read(r_cleanup_ptr.read());
     3790          bool last               = (heap_entry.next == r_cleanup_ptr.read());
     3791          bool cleanup_inst       = r_cleanup_trdid.read() & 0x1;
     3792
     3793          // match_dir computation
     3794          bool match_dir_srcid    = (r_cleanup_copy.read() == r_cleanup_srcid.read());
     3795          bool match_dir_inst     = (r_cleanup_copy_inst.read()  == cleanup_inst);
     3796          bool match_dir          = match_dir_srcid and match_dir_inst;
    34763797#if L1_MULTI_CACHE
    3477                 match_dir = match_dir and (r_cleanup_copy_cache.read() == r_cleanup_pktid.read());
    3478 #endif
    3479 
    3480                 // match_heap computation
    3481                 bool match_heap_srcid   = (heap_entry.owner.srcid == r_cleanup_srcid.read());
    3482                 bool match_heap_inst    = (heap_entry.owner.inst  == cleanup_inst);
    3483                 bool match_heap         = match_heap_srcid and match_heap_inst;
     3798          match_dir = match_dir and (r_cleanup_copy_cache.read() == r_cleanup_pktid.read());
     3799#endif
     3800
     3801          // match_heap computation
     3802          bool match_heap_srcid   = (heap_entry.owner.srcid == r_cleanup_srcid.read());
     3803          bool match_heap_inst    = (heap_entry.owner.inst  == cleanup_inst);
     3804          bool match_heap         = match_heap_srcid and match_heap_inst;
    34843805#if L1_MULTI_CACHE
    3485                 match_heap = match_heap and (heap_entry.owner.cache_id == r_cleanup_pktid.read());
    3486 #endif
    3487 
    3488                 r_cleanup_prev_ptr      = r_cleanup_ptr.read();
    3489                 r_cleanup_prev_srcid    = heap_entry.owner.srcid;
     3806          match_heap = match_heap and (heap_entry.owner.cache_id == r_cleanup_pktid.read());
     3807#endif
     3808
     3809          r_cleanup_prev_ptr      = r_cleanup_ptr.read();
     3810          r_cleanup_prev_srcid    = heap_entry.owner.srcid;
    34903811#if L1_MULTI_CACHE
    3491                 r_cleanup_prev_cache_id = heap_entry.owner.cache_id;
    3492 #endif
    3493                 r_cleanup_prev_inst     = heap_entry.owner.inst;
    3494 
    3495                 if (match_dir) // the matching copy is registered in the directory
    3496                 {       
    3497                     // the copy registered in the directory must be replaced
    3498                     // by the first copy registered in the heap
    3499                     // and the corresponding entry must be freed
    3500                     DirectoryEntry dir_entry;
    3501                     dir_entry.valid             = true;
    3502                     dir_entry.is_cnt        = r_cleanup_is_cnt.read();
    3503                     dir_entry.dirty             = r_cleanup_dirty.read();
    3504                     dir_entry.tag               = r_cleanup_tag.read();
    3505                     dir_entry.lock              = r_cleanup_lock.read();
    3506                     dir_entry.ptr           = heap_entry.next;
    3507                     dir_entry.count         = r_cleanup_count.read()-1;
    3508                     dir_entry.owner.srcid   = heap_entry.owner.srcid;
     3812          r_cleanup_prev_cache_id = heap_entry.owner.cache_id;
     3813#endif
     3814          r_cleanup_prev_inst     = heap_entry.owner.inst;
     3815
     3816          if (match_dir)
     3817          // the matching copy is registered in the directory
     3818          {
     3819            // the copy registered in the directory must be replaced
     3820            // by the first copy registered in the heap
     3821            // and the corresponding entry must be freed
     3822            DirectoryEntry dir_entry;
     3823            dir_entry.valid          = true;
     3824            dir_entry.is_cnt         = r_cleanup_is_cnt.read();
     3825            dir_entry.dirty          = r_cleanup_dirty.read();
     3826            dir_entry.tag            = r_cleanup_tag.read();
     3827            dir_entry.lock           = r_cleanup_lock.read();
     3828            dir_entry.ptr            = heap_entry.next;
     3829            dir_entry.count          = r_cleanup_count.read()-1;
     3830            dir_entry.owner.srcid    = heap_entry.owner.srcid;
    35093831#if L1_MULTI_CACHE
    3510                     dir_entry.owner.cache_id = heap_entry.owner.cache_id;
    3511 #endif
    3512                     dir_entry.owner.inst    = heap_entry.owner.inst;
    3513                     m_cache_directory.write(set,way,dir_entry);
    3514                     r_cleanup_next_ptr      = r_cleanup_ptr.read();
    3515                     r_cleanup_fsm           = CLEANUP_HEAP_FREE;
    3516                 }
    3517                 else if (match_heap) // the matching copy is the first copy in the heap
    3518                 {
    3519                     // The first copy in heap must be freed
    3520                     // and the copy registered in directory must point to the next copy in heap
    3521                     DirectoryEntry dir_entry;
    3522                     dir_entry.valid             = true;
    3523                     dir_entry.is_cnt        = r_cleanup_is_cnt.read();
    3524                     dir_entry.dirty             = r_cleanup_dirty.read();
    3525                     dir_entry.tag               = r_cleanup_tag.read();
    3526                     dir_entry.lock              = r_cleanup_lock.read();
    3527                     dir_entry.ptr           = heap_entry.next;
    3528                     dir_entry.count         = r_cleanup_count.read()-1;
    3529                     dir_entry.owner.srcid   = r_cleanup_copy.read();
     3832            dir_entry.owner.cache_id = heap_entry.owner.cache_id;
     3833#endif
     3834            dir_entry.owner.inst     = heap_entry.owner.inst;
     3835
     3836            m_cache_directory.write(set,way,dir_entry);
     3837
     3838            r_cleanup_next_ptr       = r_cleanup_ptr.read();
     3839            r_cleanup_fsm            = CLEANUP_HEAP_FREE;
     3840          }
     3841          else if (match_heap)
     3842          // the matching copy is the first copy in the heap
     3843          {
     3844            // The first copy in heap must be freed
     3845            // and the copy registered in directory must point to the next copy in heap
     3846            DirectoryEntry dir_entry;
     3847            dir_entry.valid          = true;
     3848            dir_entry.is_cnt         = r_cleanup_is_cnt.read();
     3849            dir_entry.dirty          = r_cleanup_dirty.read();
     3850            dir_entry.tag            = r_cleanup_tag.read();
     3851            dir_entry.lock           = r_cleanup_lock.read();
     3852            dir_entry.ptr            = heap_entry.next;
     3853            dir_entry.count          = r_cleanup_count.read()-1;
     3854            dir_entry.owner.srcid    = r_cleanup_copy.read();
    35303855#if L1_MULTI_CACHE
    3531                     dir_entry.owner.cache_id = r_cleanup_copy_cache.read();
    3532 #endif
    3533                     dir_entry.owner.inst    = r_cleanup_copy_inst.read();
    3534                     m_cache_directory.write(set,way,dir_entry);
    3535                     r_cleanup_next_ptr      = r_cleanup_ptr.read();
    3536                     r_cleanup_fsm           = CLEANUP_HEAP_FREE;
    3537                 }
    3538                 else if(!last) // The matching copy is in the heap, but is not the first copy
    3539                 {
    3540                     // The directory entry must be modified to decrement count
    3541                     DirectoryEntry  dir_entry;
    3542                     dir_entry.valid           = true;
    3543                     dir_entry.is_cnt      = r_cleanup_is_cnt.read();
    3544                     dir_entry.dirty           = r_cleanup_dirty.read();
    3545                     dir_entry.tag             = r_cleanup_tag.read();
    3546                     dir_entry.lock        = r_cleanup_lock.read();
    3547                     dir_entry.ptr         = r_cleanup_ptr.read();
    3548                     dir_entry.count       = r_cleanup_count.read()-1;
    3549                     dir_entry.owner.srcid = r_cleanup_copy.read();
     3856            dir_entry.owner.cache_id = r_cleanup_copy_cache.read();
     3857#endif
     3858            dir_entry.owner.inst     = r_cleanup_copy_inst.read();
     3859
     3860            m_cache_directory.write(set,way,dir_entry);
     3861
     3862            r_cleanup_next_ptr       = r_cleanup_ptr.read();
     3863            r_cleanup_fsm            = CLEANUP_HEAP_FREE;
     3864          }
     3865          else if(!last)
     3866          // The matching copy is in the heap, but is not the first copy
     3867          {
     3868            // The directory entry must be modified to decrement count
     3869            DirectoryEntry  dir_entry;
     3870            dir_entry.valid          = true;
     3871            dir_entry.is_cnt         = r_cleanup_is_cnt.read();
     3872            dir_entry.dirty          = r_cleanup_dirty.read();
     3873            dir_entry.tag            = r_cleanup_tag.read();
     3874            dir_entry.lock           = r_cleanup_lock.read();
     3875            dir_entry.ptr            = r_cleanup_ptr.read();
     3876            dir_entry.count          = r_cleanup_count.read()-1;
     3877            dir_entry.owner.srcid    = r_cleanup_copy.read();
    35503878#if L1_MULTI_CACHE
    3551                     dir_entry.owner.cache_id = r_cleanup_copy_cache.read();
    3552 #endif
    3553                     dir_entry.owner.inst     = r_cleanup_copy_inst.read();
    3554                     m_cache_directory.write(set,way,dir_entry);
    3555                     r_cleanup_next_ptr       = heap_entry.next;
    3556                     r_cleanup_fsm            = CLEANUP_HEAP_SEARCH;
    3557                 }
    3558                 else
    3559                 {
    3560                     std::cout << "VCI_MEM_CACHE ERROR " << name()
    3561                               << " CLEANUP_HEAP_LOCK state"
    3562                               << " hit but copy not found" << std::endl;
    3563                     exit(0);
    3564                 }
     3879            dir_entry.owner.cache_id = r_cleanup_copy_cache.read();
     3880#endif
     3881            dir_entry.owner.inst     = r_cleanup_copy_inst.read();
     3882
     3883            m_cache_directory.write(set,way,dir_entry);
     3884
     3885            r_cleanup_next_ptr       = heap_entry.next;
     3886            r_cleanup_fsm            = CLEANUP_HEAP_SEARCH;
     3887          }
     3888          else
     3889          {
     3890            std::cout << "VCI_MEM_CACHE ERROR " << name()
     3891              << " CLEANUP_HEAP_LOCK state"
     3892              << " hit but copy not found" << std::endl;
     3893            exit(0);
     3894          }
    35653895
    35663896#if DEBUG_MEMC_CLEANUP
    3567 if( m_debug_cleanup_fsm )
    3568 {
    3569     std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_LOCK> Checks matching:"
     3897          if( m_debug_cleanup_fsm )
     3898          {
     3899            std::cout
     3900              << "  <MEMC " << name() << ".CLEANUP_HEAP_LOCK> Checks matching:"
    35703901              << " line = " << r_cleanup_nline.read() * m_words * 4
    35713902              << " / dir_id = " << r_cleanup_copy.read()
    35723903              << " / dir_ins = " << r_cleanup_copy_inst.read()
    35733904              << " / heap_id = " << heap_entry.owner.srcid
    3574               << " / heap_ins = " << heap_entry.owner.inst
    3575               << " / search_id = " << r_cleanup_srcid.read()
    3576               << " / search_ins = " << (r_cleanup_trdid.read()&0x1) << std::endl;
    3577 }
    3578 #endif
    3579             }
    3580             break;
    3581         }
    3582         /////////////////////////
    3583         case CLEANUP_HEAP_SEARCH:  // This state is handling the case where the copy
    3584                                    // is in the heap, but is not the first in the linked list
    3585         {
    3586             if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
    3587             {
    3588                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    3589                           << " CLEANUP_HEAP_SEARCH state"
    3590                           << " bad HEAP allocation" << std::endl;
    3591                 exit(0);
    3592             }
    3593 
    3594             HeapEntry heap_entry  = m_heap.read(r_cleanup_next_ptr.read());
    3595             bool last             = (heap_entry.next == r_cleanup_next_ptr.read());
    3596             bool cleanup_inst     = r_cleanup_trdid.read() & 0x1;
    3597             bool match_heap_srcid = (heap_entry.owner.srcid == r_cleanup_srcid.read());
    3598             bool match_heap_inst  = (heap_entry.owner.inst  == cleanup_inst);
    3599             bool match_heap       = match_heap_srcid && match_heap_inst;
    3600 #if L1_MULTI_CACHE
    3601             match_heap = match_heap and (heap_entry.owner.cache_id == r_cleanup_pktid.read());
    3602 #endif
    3603 
    3604 #if DEBUG_MEMC_CLEANUP
    3605 if( m_debug_cleanup_fsm )
    3606 {
    3607     std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Cheks matching:"
    3608               << " line = " << r_cleanup_nline.read() * m_words * 4
    3609               << " / heap_id = " << heap_entry.owner.srcid
    3610               << " / heap_ins = " << heap_entry.owner.inst
    3611               << " / search_id = " << r_cleanup_srcid.read()
    3612               << " / search_ins = " << (r_cleanup_trdid.read()&0x1)
    3613               << " / last = " << last << std::endl;
    3614 }
    3615 #endif
    3616             if(match_heap) // the matching copy must be removed
    3617             {
    3618                 r_cleanup_ptr = heap_entry.next; // reuse ressources
    3619                 r_cleanup_fsm = CLEANUP_HEAP_CLEAN;
    3620             }
    3621             else
    3622             {
    3623                 if ( last )
    3624                 {
    3625                     std::cout << "VCI_MEM_CACHE_ERROR " << name()
    3626                               << " CLEANUP_HEAP_SEARCH state"
    3627                               << " cleanup hit but copy not found" << std::endl;
    3628                     exit(0);
    3629                 }
    3630                 else // test the next in the linked list
    3631                 {
    3632                     r_cleanup_prev_ptr      = r_cleanup_next_ptr.read();
    3633                     r_cleanup_prev_srcid    = heap_entry.owner.srcid;
    3634 #if L1_MULTI_CACHE
    3635                     r_cleanup_prev_cache_id = heap_entry.owner.cache_id;
    3636 #endif
    3637                     r_cleanup_prev_inst     = heap_entry.owner.inst;
    3638                     r_cleanup_next_ptr      = heap_entry.next;
    3639                     r_cleanup_fsm           = CLEANUP_HEAP_SEARCH;
    3640 
    3641 #if DEBUG_MEMC_CLEANUP
    3642 if( m_debug_cleanup_fsm )
    3643 {
    3644     std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Matching copy not found, search next:"
    3645               << " line = " << r_cleanup_nline.read() * m_words * 4
    3646               << " / heap_id = " << heap_entry.owner.srcid
    36473905              << " / heap_ins = " << heap_entry.owner.inst
    36483906              << " / search_id = " << r_cleanup_srcid.read()
    36493907              << " / search_ins = " << (r_cleanup_trdid.read()&0x1) << std::endl;
    3650 }
    3651 #endif
    3652                 }
    3653             }
    3654             break;
    3655         }
    3656         ////////////////////////
    3657         case CLEANUP_HEAP_CLEAN:  // remove a copy in the linked list
    3658         {
    3659             if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
    3660             {
    3661                 std::cout << "VCI_MEM_CACHE ERROR " << name()
    3662                           << " CLEANUP_HEAP_CLEAN state"
    3663                           << "Bad HEAP allocation" << std::endl;
    3664                 exit(0);
    3665             }
    3666 
    3667             bool last = (r_cleanup_next_ptr.read() == r_cleanup_ptr.read());
    3668             HeapEntry heap_entry;
    3669             heap_entry.owner.srcid    = r_cleanup_prev_srcid.read();
     3908          }
     3909#endif
     3910        }
     3911        else
     3912        {
     3913          std::cout << "VCI_MEM_CACHE ERROR " << name()
     3914            << " CLEANUP_HEAP_LOCK state"
     3915            << " bad HEAP allocation" << std::endl;
     3916
     3917          exit(0);
     3918        }
     3919        break;
     3920      }
     3921
     3922      /////////////////////////
     3923      case CLEANUP_HEAP_SEARCH:  // This state is handling the case where the copy
     3924      // is in the heap, but is not the first in the linked list
     3925      {
     3926        if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
     3927        {
     3928          std::cout << "VCI_MEM_CACHE ERROR " << name()
     3929            << " CLEANUP_HEAP_SEARCH state"
     3930            << " bad HEAP allocation" << std::endl;
     3931          exit(0);
     3932        }
     3933
     3934        HeapEntry heap_entry  = m_heap.read(r_cleanup_next_ptr.read());
     3935        bool last             = (heap_entry.next == r_cleanup_next_ptr.read());
     3936        bool cleanup_inst     = r_cleanup_trdid.read() & 0x1;
     3937        bool match_heap_srcid = (heap_entry.owner.srcid == r_cleanup_srcid.read());
     3938        bool match_heap_inst  = (heap_entry.owner.inst  == cleanup_inst);
     3939        bool match_heap       = match_heap_srcid && match_heap_inst;
    36703940#if L1_MULTI_CACHE
    3671             heap_entry.owner.cache_id = r_cleanup_prev_cache_id.read();
    3672 #endif
    3673             heap_entry.owner.inst     = r_cleanup_prev_inst.read();
    3674             if(last) // this is the last entry of the list of copies
    3675             {
    3676                 heap_entry.next     = r_cleanup_prev_ptr.read();
    3677             }
    3678             else  // this is not the last entry
    3679             {
    3680                 heap_entry.next     = r_cleanup_ptr.read();
    3681             }
    3682             m_heap.write(r_cleanup_prev_ptr.read(),heap_entry);
    3683             r_cleanup_fsm = CLEANUP_HEAP_FREE;
     3941        match_heap = match_heap and (heap_entry.owner.cache_id == r_cleanup_pktid.read());
     3942#endif
    36843943
    36853944#if DEBUG_MEMC_CLEANUP
    3686 if( m_debug_cleanup_fsm )
    3687 {
    3688     std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Remove the copy in the linked list" << std::endl;
    3689 }
    3690 #endif
    3691             break;
    3692         }
    3693         ///////////////////////
    3694         case CLEANUP_HEAP_FREE:  // The heap entry pointed by r_cleanup_next_ptr is freed
    3695                                  // and becomes the head of the list of free entries
    3696         {
    3697             if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
    3698             {
    3699                 std::cout << "VCI_MEM_CACHE ERROR " << name() << " CLEANUP_HEAP_CLEAN state" << std::endl;
    3700                 std::cout << "Bad HEAP allocation" << std::endl;
    3701                 exit(0);
    3702             }
    3703 
    3704             HeapEntry heap_entry;
    3705             heap_entry.owner.srcid    = 0;
     3945        if( m_debug_cleanup_fsm )
     3946        {
     3947          std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Cheks matching:"
     3948            << " line = " << r_cleanup_nline.read() * m_words * 4
     3949            << " / heap_id = " << heap_entry.owner.srcid
     3950            << " / heap_ins = " << heap_entry.owner.inst
     3951            << " / search_id = " << r_cleanup_srcid.read()
     3952            << " / search_ins = " << (r_cleanup_trdid.read()&0x1)
     3953            << " / last = " << last << std::endl;
     3954        }
     3955#endif
     3956        if(match_heap) // the matching copy must be removed
     3957        {
     3958          r_cleanup_ptr = heap_entry.next; // reuse ressources
     3959          r_cleanup_fsm = CLEANUP_HEAP_CLEAN;
     3960        }
     3961        else
     3962        {
     3963          if ( last )
     3964          {
     3965            std::cout << "VCI_MEM_CACHE_ERROR " << name()
     3966              << " CLEANUP_HEAP_SEARCH state"
     3967              << " cleanup hit but copy not found" << std::endl;
     3968            exit(0);
     3969          }
     3970          else // test the next in the linked list
     3971          {
     3972            r_cleanup_prev_ptr      = r_cleanup_next_ptr.read();
     3973            r_cleanup_prev_srcid    = heap_entry.owner.srcid;
    37063974#if L1_MULTI_CACHE
    3707             heap_entry.owner.cache_id = 0;
    3708 #endif
    3709             heap_entry.owner.inst     = false;
    3710 
    3711             if(m_heap.is_full()) heap_entry.next     = r_cleanup_next_ptr.read();
    3712             else                           heap_entry.next     = m_heap.next_free_ptr();
    3713             m_heap.write(r_cleanup_next_ptr.read(),heap_entry);
    3714             m_heap.write_free_ptr(r_cleanup_next_ptr.read());
    3715             m_heap.unset_full();
     3975            r_cleanup_prev_cache_id = heap_entry.owner.cache_id;
     3976#endif
     3977            r_cleanup_prev_inst     = heap_entry.owner.inst;
     3978            r_cleanup_next_ptr      = heap_entry.next;
     3979            r_cleanup_fsm           = CLEANUP_HEAP_SEARCH;
     3980
     3981#if DEBUG_MEMC_CLEANUP
     3982            if( m_debug_cleanup_fsm )
     3983            {
     3984              std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Matching copy not found, search next:"
     3985                << " line = " << r_cleanup_nline.read() * m_words * 4
     3986                << " / heap_id = " << heap_entry.owner.srcid
     3987                << " / heap_ins = " << heap_entry.owner.inst
     3988                << " / search_id = " << r_cleanup_srcid.read()
     3989                << " / search_ins = " << (r_cleanup_trdid.read()&0x1) << std::endl;
     3990            }
     3991#endif
     3992          }
     3993        }
     3994        break;
     3995      }
     3996
     3997      ////////////////////////
     3998      case CLEANUP_HEAP_CLEAN:  // remove a copy in the linked list
     3999      {
     4000        if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
     4001        {
     4002          std::cout << "VCI_MEM_CACHE ERROR " << name()
     4003            << " CLEANUP_HEAP_CLEAN state"
     4004            << "Bad HEAP allocation" << std::endl;
     4005          exit(0);
     4006        }
     4007
     4008        bool last = (r_cleanup_next_ptr.read() == r_cleanup_ptr.read());
     4009        HeapEntry heap_entry;
     4010        heap_entry.owner.srcid    = r_cleanup_prev_srcid.read();
     4011#if L1_MULTI_CACHE
     4012        heap_entry.owner.cache_id = r_cleanup_prev_cache_id.read();
     4013#endif
     4014        heap_entry.owner.inst     = r_cleanup_prev_inst.read();
     4015       
     4016        if(last) // this is the last entry of the list of copies
     4017        {
     4018          heap_entry.next     = r_cleanup_prev_ptr.read();
     4019        }
     4020        else  // this is not the last entry
     4021        {
     4022          heap_entry.next     = r_cleanup_ptr.read();
     4023        }
     4024
     4025        m_heap.write(r_cleanup_prev_ptr.read(),heap_entry);
     4026        r_cleanup_fsm = CLEANUP_HEAP_FREE;
     4027
     4028#if DEBUG_MEMC_CLEANUP
     4029        if( m_debug_cleanup_fsm )
     4030        {
     4031          std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Remove the copy in the linked list" << std::endl;
     4032        }
     4033#endif
     4034        break;
     4035      }
     4036
     4037      ///////////////////////
     4038      case CLEANUP_HEAP_FREE:
     4039      // The heap entry pointed by r_cleanup_next_ptr is freed
     4040      // and becomes the head of the list of free entries
     4041      {
     4042        if ( r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP )
     4043        {
     4044          std::cout
     4045            << "VCI_MEM_CACHE ERROR " << name()
     4046            << " CLEANUP_HEAP_CLEAN state" << std::endl
     4047            << "Bad HEAP allocation" << std::endl;
     4048
     4049          exit(0);
     4050        }
     4051
     4052        HeapEntry heap_entry;
     4053        heap_entry.owner.srcid    = 0;
     4054#if L1_MULTI_CACHE
     4055        heap_entry.owner.cache_id = 0;
     4056#endif
     4057        heap_entry.owner.inst     = false;
     4058
     4059        if(m_heap.is_full())
     4060        {
     4061          heap_entry.next = r_cleanup_next_ptr.read();
     4062        }
     4063        else
     4064        {
     4065          heap_entry.next = m_heap.next_free_ptr();
     4066        }
     4067
     4068        m_heap.write(r_cleanup_next_ptr.read(),heap_entry);
     4069        m_heap.write_free_ptr(r_cleanup_next_ptr.read());
     4070        m_heap.unset_full();
     4071
     4072        r_cleanup_fsm = CLEANUP_RSP;
     4073
     4074#if DEBUG_MEMC_CLEANUP
     4075        if( m_debug_cleanup_fsm )
     4076        {
     4077          std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Update the list of free entries" << std::endl;
     4078        }
     4079#endif
     4080        break;
     4081      }
     4082
     4083      //////////////////////
     4084      case CLEANUP_UPT_LOCK:
     4085      {
     4086        if ( r_alloc_upt_fsm.read() == ALLOC_UPT_CLEANUP )
     4087        {
     4088          size_t index = 0;
     4089          bool hit_inval;
     4090          hit_inval = m_update_tab.search_inval(r_cleanup_nline.read(),index);
     4091
     4092          if ( !hit_inval ) // no pending inval
     4093          {
     4094
     4095#if DEBUG_MEMC_CLEANUP
     4096            if( m_debug_cleanup_fsm )
     4097            {
     4098              std::cout << "  <MEMC " << name() << ".CLEANUP_UPT_LOCK> Unexpected cleanup with no corresponding UPT entry:"
     4099                << " address = " << std::hex << (r_cleanup_nline.read()*4*m_words) << std::endl;
     4100            }
     4101#endif
    37164102            r_cleanup_fsm = CLEANUP_RSP;
     4103          }
     4104          else    // pending inval
     4105          {
     4106            r_cleanup_write_srcid = m_update_tab.srcid(index);
     4107            r_cleanup_write_trdid = m_update_tab.trdid(index);
     4108            r_cleanup_write_pktid = m_update_tab.pktid(index);
     4109            r_cleanup_need_rsp    = m_update_tab.need_rsp(index);
     4110            r_cleanup_fsm = CLEANUP_UPT_WRITE;
     4111          }
     4112          r_cleanup_index.write(index) ;
     4113        }
     4114        break;
     4115      }
     4116
     4117      ///////////////////////
     4118      case CLEANUP_UPT_WRITE:  // decrement response counter
     4119      {
     4120        size_t count = 0;
     4121        m_update_tab.decrement(r_cleanup_index.read(), count);
     4122        if ( count == 0 )
     4123        {
     4124          m_update_tab.clear(r_cleanup_index.read());
    37174125
    37184126#if DEBUG_MEMC_CLEANUP
    3719 if( m_debug_cleanup_fsm )
    3720 {
    3721     std::cout << "  <MEMC " << name() << ".CLEANUP_HEAP_SEARCH> Update the list of free entries" << std::endl;
    3722 }
    3723 #endif
    3724             break;
    3725         }
    3726         //////////////////////
    3727         case CLEANUP_UPT_LOCK:
    3728         {
    3729             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_CLEANUP )
    3730             {
    3731                 size_t index = 0;
    3732                 bool hit_inval;
    3733                 hit_inval = m_update_tab.search_inval(r_cleanup_nline.read(),index);
    3734 
    3735                 if ( !hit_inval ) // no pending inval
    3736                 {
    3737 
    3738 #if DEBUG_MEMC_CLEANUP
    3739 if( m_debug_cleanup_fsm )
    3740 {
    3741     std::cout << "  <MEMC " << name() << ".CLEANUP_UPT_LOCK> Unexpected cleanup with no corresponding UPT entry:"
    3742               << " address = " << std::hex << (r_cleanup_nline.read()*4*m_words) << std::endl;
    3743 }
    3744 #endif
    3745                     r_cleanup_fsm = CLEANUP_RSP;
    3746                 }
    3747                 else            // pending inval
    3748                 {
    3749                     r_cleanup_write_srcid = m_update_tab.srcid(index);
    3750                     r_cleanup_write_trdid = m_update_tab.trdid(index);
    3751                     r_cleanup_write_pktid = m_update_tab.pktid(index);
    3752                     r_cleanup_need_rsp    = m_update_tab.need_rsp(index);
    3753                     r_cleanup_fsm = CLEANUP_UPT_WRITE;
    3754                 }
    3755                 r_cleanup_index.write(index) ;
    3756             }
    3757             break;
    3758         }
    3759         ///////////////////////
    3760         case CLEANUP_UPT_WRITE:  // decrement response counter
    3761         {
    3762             size_t count = 0;
    3763             m_update_tab.decrement(r_cleanup_index.read(), count);
    3764             if ( count == 0 )
    3765             {
    3766                 m_update_tab.clear(r_cleanup_index.read());
    3767 
    3768 #if DEBUG_MEMC_CLEANUP
    3769 if( m_debug_cleanup_fsm )
    3770 {
    3771     std::cout << "  <MEMC " << name() << ".CLEANUP_UPT_WRITE> Decrement response counter in UPT:"
     4127          if( m_debug_cleanup_fsm )
     4128          {
     4129            std::cout << "  <MEMC " << name() << ".CLEANUP_UPT_WRITE> Decrement response counter in UPT:"
    37724130              << " UPT_index = " << r_cleanup_index.read()
    37734131              << " rsp_count = " << count << std::endl;
    3774 }
    3775 #endif
    3776                 if( r_cleanup_need_rsp.read() ) r_cleanup_fsm = CLEANUP_WRITE_RSP ; 
    3777                 else                                        r_cleanup_fsm = CLEANUP_RSP;
    3778             }
    3779             else
    3780             {
    3781                 r_cleanup_fsm = CLEANUP_RSP ;
    3782             }
    3783             break;
    3784         }
    3785         ///////////////////////
    3786         case CLEANUP_WRITE_RSP: // Response to a previous write on the direct network
    3787         {
    3788             if( !r_cleanup_to_tgt_rsp_req.read() )
    3789             {
    3790                 r_cleanup_to_tgt_rsp_req     = true;
    3791                 r_cleanup_to_tgt_rsp_srcid   = r_cleanup_write_srcid.read();
    3792                 r_cleanup_to_tgt_rsp_trdid   = r_cleanup_write_trdid.read();
    3793                 r_cleanup_to_tgt_rsp_pktid   = r_cleanup_write_pktid.read();
    3794                 r_cleanup_fsm                = CLEANUP_RSP;
     4132          }
     4133#endif
     4134          if( r_cleanup_need_rsp.read() ) r_cleanup_fsm = CLEANUP_WRITE_RSP ;
     4135          else                      r_cleanup_fsm = CLEANUP_RSP;
     4136        }
     4137        else
     4138        {
     4139          r_cleanup_fsm = CLEANUP_RSP ;
     4140        }
     4141        break;
     4142      }
     4143
     4144      ///////////////////////
     4145      case CLEANUP_WRITE_RSP: // Response to a previous write on the direct network
     4146      {
     4147        if( !r_cleanup_to_tgt_rsp_req.read() )
     4148        {
     4149          r_cleanup_to_tgt_rsp_req     = true;
     4150          r_cleanup_to_tgt_rsp_srcid   = r_cleanup_write_srcid.read();
     4151          r_cleanup_to_tgt_rsp_trdid   = r_cleanup_write_trdid.read();
     4152          r_cleanup_to_tgt_rsp_pktid   = r_cleanup_write_pktid.read();
     4153          r_cleanup_fsm                = CLEANUP_RSP;
    37954154
    37964155#if DEBUG_MEMC_CLEANUP
    3797 if( m_debug_cleanup_fsm )
    3798 {
    3799     std::cout << "  <MEMC " << name() << ".CLEANUP_WRITE_RSP> Send a response to a cleanup request:"
     4156          if( m_debug_cleanup_fsm )
     4157          {
     4158            std::cout << "  <MEMC " << name() << ".CLEANUP_WRITE_RSP> Send a response to a cleanup request:"
    38004159              << " rsrcid = " << std::dec << r_cleanup_write_srcid.read()
    38014160              << " / rtrdid = " << std::dec << r_cleanup_write_trdid.read() << std::endl;
    3802 }
    3803 #endif
    3804             }
    3805             break;
    3806         }
    3807         /////////////////
    3808         case CLEANUP_RSP:       // Response to a cleanup on the coherence network
    3809         {
    3810             if ( p_vci_tgt_cleanup.rspack.read() )
    3811             {
    3812                 r_cleanup_fsm = CLEANUP_IDLE;
     4161          }
     4162#endif
     4163        }
     4164        break;
     4165      }
     4166
     4167      /////////////////
     4168      case CLEANUP_RSP: // Response to a cleanup on the coherence network
     4169      {
     4170        if ( p_vci_tgt_cleanup.rspack.read() )
     4171        {
     4172          r_cleanup_fsm = CLEANUP_IDLE;
    38134173
    38144174#if DEBUG_MEMC_CLEANUP
    3815 if( m_debug_cleanup_fsm )
    3816 {
    3817     std::cout << "  <MEMC " << name() << ".CLEANUP_RSP> Send the response to a cleanup request:"
     4175          if( m_debug_cleanup_fsm )
     4176          {
     4177            std::cout << "  <MEMC " << name() << ".CLEANUP_RSP> Send the response to a cleanup request:"
    38184178              << " rsrcid = " << std::dec << r_cleanup_write_srcid.read()
    38194179              << " / rtrdid = " << r_cleanup_write_trdid.read() << std::endl;
    3820 }
    3821 #endif
    3822             }
    3823             break;
    3824         }
     4180          }
     4181#endif
     4182        }
     4183        break;
     4184      }
    38254185    } // end switch cleanup fsm
    38264186
    38274187    ////////////////////////////////////////////////////////////////////////////////////
    3828     //          SC FSM
     4188    //    SC FSM
    38294189    ////////////////////////////////////////////////////////////////////////////////////
    3830     // The SC FSM handles the SC (Store Conditionnal) atomic commands, 
     4190    // The SC FSM handles the SC (Store Conditionnal) atomic commands,
    38314191    // that are handled as "compare-and-swap instructions.
    3832     // 
    3833     // This command contains two or four flits: 
     4192    //
     4193    // This command contains two or four flits:
    38344194    // - In case of 32 bits atomic access, the first flit contains the value read
    38354195    // by a previous LL instruction, the second flit contains the value to be writen.
    38364196    // - In case of 64 bits atomic access, the 2 first flits contains the value read
    38374197    // by a previous LL instruction, the 2 next flits contains the value to be writen.
    3838     // 
     4198    //
    38394199    // The target address is cachable. If it is replicated in other L1 caches
    38404200    // than the writer, a coherence operation is done.
    3841     // 
     4201    //
    38424202    // It access the directory to check hit / miss.
    38434203    // - In case of miss, the SC FSM must register a GET transaction in TRT.
    3844     // If a read transaction to the XRAM for this line already exists, 
     4204    // If a read transaction to the XRAM for this line already exists,
    38454205    // or if the transaction table is full, it goes to the WAIT state
    38464206    // to release the locks and try again. When the GET transaction has been
     
    38504210    ///////////////////////////////////////////////////////////////////////////////////
    38514211
    3852     switch ( r_sc_fsm.read() ) 
     4212    switch ( r_sc_fsm.read() )
    38534213    {
    38544214        /////////////
    3855         case SC_IDLE:       // fill the local rdata buffers
    3856         {
    3857             if( m_cmd_sc_addr_fifo.rok() ) 
     4215        case SC_IDLE:     // fill the local rdata buffers
     4216        {
     4217            if( m_cmd_sc_addr_fifo.rok() )
    38584218            {
    38594219
     
    38624222{
    38634223    std::cout << "  <MEMC " << name() << ".SC_IDLE> SC command: " << std::hex
    3864               << " srcid = " <<  std::dec << m_cmd_sc_srcid_fifo.read() 
    3865               << " addr = " << std::hex << m_cmd_sc_addr_fifo.read() 
     4224              << " srcid = " <<  std::dec << m_cmd_sc_srcid_fifo.read()
     4225              << " addr = " << std::hex << m_cmd_sc_addr_fifo.read()
    38664226              << " wdata = " << m_cmd_sc_wdata_fifo.read()
    38674227              << " eop = " << std::dec << m_cmd_sc_eop_fifo.read()
     
    38724232                {
    38734233                    m_cpt_sc++;
    3874                     r_sc_fsm = SC_DIR_LOCK;
    3875                 } 
     4234                    r_sc_fsm = SC_DIR_REQ;
     4235                }
    38764236                else  // we keep the last word in the FIFO
    38774237                {
     
    38874247                if( r_sc_cpt.read()>3 ) // more than 4 flits...
    38884248                {
    3889                     std::cout << "VCI_MEM_CACHE ERROR in SC_IDLE state : illegal SC command" 
     4249                    std::cout << "VCI_MEM_CACHE ERROR in SC_IDLE state : illegal SC command"
    38904250                              << std::endl;
    38914251                    exit(0);
     
    38964256
    38974257                r_sc_cpt = r_sc_cpt.read()+1;
    3898             }   
     4258            }
    38994259            break;
    39004260        }
     4261       
     4262        /////////////////
     4263        case SC_DIR_REQ:
     4264        {
     4265            if( r_alloc_dir_fsm.read() == ALLOC_DIR_SC )
     4266            {
     4267              r_sc_fsm = SC_DIR_LOCK;
     4268            }
     4269
     4270#if DEBUG_MEMC_SC
     4271            if( m_debug_sc_fsm )
     4272            {
     4273              std::cout
     4274                << "  <MEMC " << name() << ".SC_DIR_REQ> Requesting DIR lock "
     4275                << std::endl;
     4276            }
     4277#endif
     4278            break;
     4279        }
     4280
    39014281        /////////////////
    39024282        case SC_DIR_LOCK:  // Read the directory
    39034283        {
    3904             if( r_alloc_dir_fsm.read() == ALLOC_DIR_SC ) 
     4284            if( r_alloc_dir_fsm.read() == ALLOC_DIR_SC )
    39054285            {
    39064286                size_t way = 0;
     
    39194299                r_sc_count      = entry.count;
    39204300
    3921                 if ( entry.valid )      r_sc_fsm = SC_DIR_HIT_READ;
    3922                 else                        r_sc_fsm = SC_MISS_TRT_LOCK;
     4301                if ( entry.valid )  r_sc_fsm = SC_DIR_HIT_READ;
     4302                else          r_sc_fsm = SC_MISS_TRT_LOCK;
    39234303
    39244304#if DEBUG_MEMC_SC
     
    39274307    std::cout << "  <MEMC " << name() << ".SC_DIR_LOCK> Directory acces"
    39284308              << " / address = " << std::hex << m_cmd_sc_addr_fifo.read()
    3929               << " / hit = " << std::dec << entry.valid 
     4309              << " / hit = " << std::dec << entry.valid
    39304310              << " / count = " << entry.count
    39314311              << " / is_cnt = " << entry.is_cnt << std::endl;
     
    39334313#endif
    39344314            }
     4315            else
     4316            {
     4317              std::cout
     4318                << "VCI_MEM_CACHE ERROR " << name()
     4319                << " SC_DIR_LOCK state" << std::endl
     4320                << "Bad DIR allocation"   << std::endl;
     4321
     4322              exit(0);
     4323            }
     4324
    39354325            break;
    39364326        }
     
    39394329                               // and check data change in cache
    39404330        {
    3941             size_t way  = r_sc_way.read();
    3942             size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    3943             size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4331            size_t way  = r_sc_way.read();
     4332            size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4333            size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    39444334
    39454335            // update directory (lock & dirty bits)
    39464336            DirectoryEntry entry;
    3947             entry.valid          = true;
     4337            entry.valid          = true;
    39484338            entry.is_cnt         = r_sc_is_cnt.read();
    3949             entry.dirty          = true;
    3950             entry.lock           = true;
    3951             entry.tag            = r_sc_tag.read();
     4339            entry.dirty          = true;
     4340            entry.lock           = true;
     4341            entry.tag          = r_sc_tag.read();
    39524342            entry.owner.srcid    = r_sc_copy.read();
    39534343#if L1_MULTI_CACHE
     
    39654355                ok &= ( r_sc_rdata[1] == m_cache_data[way][set][word+1] );
    39664356
    3967             // to avoid livelock, force the atomic access to fail pseudo-randomly 
     4357            // to avoid livelock, force the atomic access to fail pseudo-randomly
    39684358            bool forced_fail = ( (r_sc_lfsr % (64) == 0) && RANDOMIZE_SC );
    39694359            r_sc_lfsr = (r_sc_lfsr >> 1) ^ ((-(r_sc_lfsr & 1)) & 0xd0000001);
    39704360
    3971             if( ok and not forced_fail )        // no data change
     4361            if( ok and not forced_fail )  // no data change
    39724362            {
    39734363                r_sc_fsm = SC_DIR_HIT_WRITE;
     
    39764366            {
    39774367                r_sc_fsm = SC_RSP_FAIL;
    3978             } 
     4368            }
    39794369
    39804370#if DEBUG_MEMC_SC
    39814371if( m_debug_sc_fsm )
    39824372{
    3983     std::cout << "  <MEMC " << name() << ".SC_DIR_HIT_READ> Test if SC success:" 
     4373    std::cout << "  <MEMC " << name() << ".SC_DIR_HIT_READ> Test if SC success:"
    39844374              << " / expected value = " << r_sc_rdata[0].read()
    39854375              << " / actual value = " << m_cache_data[way][set][word]
     
    39904380        }
    39914381        //////////////////////
    3992         case SC_DIR_HIT_WRITE:          // test if a CC transaction is required
     4382        case SC_DIR_HIT_WRITE:    // test if a CC transaction is required
    39934383                                    // write data in cache if no CC request
    39944384        {
    39954385            // test coherence request
    3996             if(r_sc_count.read())   // replicated line 
     4386            if(r_sc_count.read())   // replicated line
    39974387            {
    39984388                if ( r_sc_is_cnt.read() )
    39994389                {
    4000                     r_sc_fsm = SC_BC_TRT_LOCK;          // broadcast invalidate required
     4390                    r_sc_fsm = SC_BC_TRT_LOCK;    // broadcast invalidate required
    40014391                }
    4002                 else if( !r_sc_to_init_cmd_multi_req.read() && 
     4392                else if( !r_sc_to_init_cmd_multi_req.read() &&
    40034393                         !r_sc_to_init_cmd_brdcast_req.read()  )
    40044394                {
    4005                     r_sc_fsm = SC_UPT_LOCK;                     // multi update required
     4395                    r_sc_fsm = SC_UPT_LOCK;     // multi update required
    40064396                }
    40074397                else
     
    40094399                    r_sc_fsm = SC_WAIT;
    40104400                }
    4011             } 
    4012             else                    // no copies 
    4013             {
    4014                 size_t way      = r_sc_way.read();
    4015                 size_t set      = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    4016                 size_t word     = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4401            }
     4402            else                    // no copies
     4403            {
     4404                size_t way  = r_sc_way.read();
     4405                size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4406                size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    40174407
    40184408                // cache update
     
    40224412
    40234413                // monitor
    4024                 if ( m_monitor_ok ) 
     4414                if ( m_monitor_ok )
    40254415                {
    40264416                    vci_addr_t address = m_cmd_sc_addr_fifo.read();
    4027                             char buf[80];
    4028                             snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
     4417                char buf[80];
     4418                snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
    40294419                    check_monitor( buf, address, r_sc_wdata.read() );
    40304420                    if ( r_sc_cpt.read()==4 )
     
    40364426if( m_debug_sc_fsm )
    40374427{
    4038     std::cout << "  <MEMC " << name() << ".SC_DIR_HIT_WRITE> Update cache:" 
     4428    std::cout << "  <MEMC " << name() << ".SC_DIR_HIT_WRITE> Update cache:"
    40394429              << " way = " << std::dec << way
    40404430              << " / set = " << set
     
    40524442                           // releases locks to retry later if UPT full
    40534443        {
    4054             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_SC ) 
     4444            if ( r_alloc_upt_fsm.read() == ALLOC_UPT_SC )
    40554445            {
    40564446                bool        wok        = false;
     
    40594449                size_t      trdid      = m_cmd_sc_trdid_fifo.read();
    40604450                size_t      pktid      = m_cmd_sc_pktid_fifo.read();
    4061                 addr_t      nline      = m_nline[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4451                addr_t      nline      = m_nline[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    40624452                size_t      nb_copies  = r_sc_count.read();
    40634453
    4064                 wok = m_update_tab.set(true,    // it's an update transaction
     4454                wok = m_update_tab.set(true,  // it's an update transaction
    40654455                                       false,   // it's not a broadcast
    40664456                                       true,    // it needs a response
     
    40744464                {
    40754465                    // cache update
    4076                     size_t way  = r_sc_way.read();
    4077                     size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    4078                     size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4466                    size_t way  = r_sc_way.read();
     4467                    size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4468                    size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    40794469
    40804470                    m_cache_data[way][set][word] = r_sc_wdata.read();
     
    40834473
    40844474                    // monitor
    4085                     if ( m_monitor_ok ) 
    4086                     { 
     4475                    if ( m_monitor_ok )
     4476                    {
    40874477                        vci_addr_t address = m_cmd_sc_addr_fifo.read();
    4088                                 char buf[80];
    4089                                 snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
     4478                    char buf[80];
     4479                    snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
    40904480                        check_monitor( buf, address, r_sc_wdata.read() );
    40914481                        if ( r_sc_cpt.read()==4 )
     
    41044494if( m_debug_sc_fsm )
    41054495{
    4106     std::cout << "  <MEMC " << name() << ".SC_UPT_LOCK> Register multi-update transaction in UPT" 
     4496    std::cout << "  <MEMC " << name() << ".SC_UPT_LOCK> Register multi-update transaction in UPT"
    41074497              << " / wok = " << wok
    4108               << " / nline  = " << std::hex << nline 
     4498              << " / nline  = " << std::hex << nline
    41094499              << " / count = " << nb_copies << std::endl;
    41104500}
     
    41144504        }
    41154505        /////////////
    4116         case SC_WAIT:   // release all locks and retry from beginning
     4506        case SC_WAIT:   // release all locks and retry from beginning
    41174507        {
    41184508
     
    41234513}
    41244514#endif
    4125             r_sc_fsm = SC_DIR_LOCK;
     4515            r_sc_fsm = SC_DIR_REQ;
    41264516            break;
    41274517        }
    41284518        //////////////////
    4129         case SC_UPT_HEAP_LOCK:  // lock the heap
    4130         {
    4131             if( r_alloc_heap_fsm.read() == ALLOC_HEAP_SC ) 
     4519        case SC_UPT_HEAP_LOCK:  // lock the heap
     4520        {
     4521            if( r_alloc_heap_fsm.read() == ALLOC_HEAP_SC )
    41324522            {
    41334523
     
    41434533        }
    41444534        ////////////////
    4145         case SC_UPT_REQ:        // send a first update request to INIT_CMD FSM
     4535        case SC_UPT_REQ:  // send a first update request to INIT_CMD FSM
    41464536        {
    41474537            assert((r_alloc_heap_fsm.read() == ALLOC_HEAP_SC) and
     
    41604550                    r_sc_to_init_cmd_is_long    = true;
    41614551                    r_sc_to_init_cmd_wdata_high = m_cmd_sc_wdata_fifo.read();
    4162                 } 
    4163                 else 
     4552                }
     4553                else
    41644554                {
    41654555                    r_sc_to_init_cmd_is_long    = false;
     
    41814571                    r_sc_to_init_cmd_multi_req = true;
    41824572                    r_sc_cpt = 0;
    4183                 } 
    4184                 else                    // several copies
     4573                }
     4574                else      // several copies
    41854575                {
    41864576                    r_sc_fsm = SC_UPT_NEXT;
     
    41904580if( m_debug_sc_fsm )
    41914581{
    4192     std::cout << "  <MEMC " << name() << ".SC_UPT_REQ> Send the first update request to INIT_CMD FSM " 
     4582    std::cout << "  <MEMC " << name() << ".SC_UPT_REQ> Send the first update request to INIT_CMD FSM "
    41934583              << " / address = " << std::hex << m_cmd_sc_addr_fifo.read()
    41944584              << " / wdata = " << std::hex << r_sc_wdata.read()
    4195               << " / srcid = " << std::dec << r_sc_copy.read() 
     4585              << " / srcid = " << std::dec << r_sc_copy.read()
    41964586              << " / inst = " << std::dec << r_sc_copy_inst.read() << std::endl;
    41974587}
     
    42014591        }
    42024592        /////////////////
    4203         case SC_UPT_NEXT:       // send a multi-update request to INIT_CMD FSM
     4593        case SC_UPT_NEXT:     // send a multi-update request to INIT_CMD FSM
    42044594        {
    42054595            assert((r_alloc_heap_fsm.read() == ALLOC_HEAP_SC)
     
    42244614                    cmd_sc_fifo_get = true;
    42254615                    r_sc_cpt        = 0;
    4226                 } 
    4227             } 
     4616                }
     4617            }
    42284618
    42294619#if DEBUG_MEMC_SC
    42304620if( m_debug_sc_fsm )
    42314621{
    4232     std::cout << "  <MEMC " << name() << ".SC_UPT_NEXT> Send the next update request to INIT_CMD FSM " 
     4622    std::cout << "  <MEMC " << name() << ".SC_UPT_NEXT> Send the next update request to INIT_CMD FSM "
    42334623              << " / address = " << std::hex << m_cmd_sc_addr_fifo.read()
    42344624              << " / wdata = " << std::hex << r_sc_wdata.read()
     
    42404630        }
    42414631        /////////////////////
    4242         case SC_BC_TRT_LOCK:            // check the TRT to register a PUT transaction     
    4243         {
    4244             if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC ) 
     4632        case SC_BC_TRT_LOCK:      // check the TRT to register a PUT transaction
     4633        {
     4634            if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC )
    42454635            {
    42464636                if( !r_sc_to_ixr_cmd_req )  // we can transfer the request to IXR_CMD FSM
    42474637                {
    42484638                    // fill the data buffer
    4249                     size_t way  = r_sc_way.read();
    4250                     size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4639                    size_t way  = r_sc_way.read();
     4640                    size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    42514641                        size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    42524642                    for(size_t i = 0; i<m_words; i++)
    42534643                    {
    4254                         if (i == word) 
     4644                        if (i == word)
    42554645                        {
    42564646                            r_sc_to_ixr_cmd_data[i] = r_sc_wdata.read();
    4257                         } 
     4647                        }
    42584648                        else if ( (i == word+1) && (r_sc_cpt.read()==4) ) // 64 bit SC
    42594649                        {
    42604650                            r_sc_to_ixr_cmd_data[i] = m_cmd_sc_wdata_fifo.read();
    4261                         } 
    4262                         else 
     4651                        }
     4652                        else
    42634653                        {
    42644654                            r_sc_to_ixr_cmd_data[i] = m_cache_data[way][set][i];
     
    42674657                    size_t wok_index = 0;
    42684658                    bool   wok       = !m_transaction_tab.full(wok_index);
    4269                     if ( wok ) 
     4659                    if ( wok )
    42704660                    {
    42714661                        r_sc_trt_index = wok_index;
    4272                         r_sc_fsm       = SC_BC_UPT_LOCK; 
    4273                     } 
    4274                     else 
     4662                        r_sc_fsm       = SC_BC_UPT_LOCK;
     4663                    }
     4664                    else
    42754665                    {
    42764666                        r_sc_fsm       = SC_WAIT;
    42774667                    }
    4278                 } 
    4279                 else 
     4668                }
     4669                else
    42804670                {
    42814671                    r_sc_fsm = SC_WAIT;
     
    42884678                              // write data in cache in case of successful registration
    42894679        {
    4290             if ( r_alloc_upt_fsm.read() == ALLOC_UPT_SC ) 
     4680            if ( r_alloc_upt_fsm.read() == ALLOC_UPT_SC )
    42914681            {
    42924682                bool        wok       = false;
     
    42954685                size_t      trdid     = m_cmd_sc_trdid_fifo.read();
    42964686                size_t      pktid     = m_cmd_sc_pktid_fifo.read();
    4297                 addr_t      nline     = m_nline[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4687                addr_t      nline     = m_nline[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    42984688                size_t      nb_copies = r_sc_count.read();
    42994689
    43004690                // register a broadcast inval transaction in UPT
    4301                 wok = m_update_tab.set(false,   // it's an inval transaction
     4691                wok = m_update_tab.set(false, // it's an inval transaction
    43024692                                       true,    // it's a broadcast
    43034693                                       true,    // it needs a response
     
    43084698                                       nb_copies,
    43094699                                       index);
    4310                
    4311                 if ( wok )      // UPT not full
     4700
     4701                if ( wok )  // UPT not full
    43124702                {
    43134703                    // cache update
    4314                     size_t way  = r_sc_way.read();
    4315                     size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    4316                     size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4704                    size_t way  = r_sc_way.read();
     4705                    size_t set  = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4706                    size_t word = m_x[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    43174707
    43184708                    m_cache_data[way][set][word] = r_sc_wdata.read();
     
    43214711
    43224712                    // monitor
    4323                     if ( m_monitor_ok ) 
    4324                     { 
     4713                    if ( m_monitor_ok )
     4714                    {
    43254715                        vci_addr_t address = m_cmd_sc_addr_fifo.read();
    4326                                 char buf[80];
    4327                                 snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
     4716                    char buf[80];
     4717                    snprintf(buf, 80, "SC_DIR_HIT_WRITE srcid %d", m_cmd_sc_srcid_fifo.read());
    43284718                        check_monitor( buf, address, r_sc_wdata.read() );
    43294719                        if ( r_sc_cpt.read()==4 )
     
    43364726{
    43374727    std::cout << "  <MEMC " << name() << ".SC_BC_UPT_LOCK> Register a broadcast inval transaction in UPT"
    4338               << " / nline = " << nline 
    4339               << " / count = " << nb_copies 
    4340               << " / upt_index = " << index << std::endl; 
     4728              << " / nline = " << nline
     4729              << " / count = " << nb_copies
     4730              << " / upt_index = " << index << std::endl;
    43414731}
    43424732#endif
     
    43584748                // set TRT
    43594749                m_transaction_tab.set(r_sc_trt_index.read(),
    4360                                       false,            // PUT request to XRAM
     4750                                      false,    // PUT request to XRAM
    43614751                                      m_nline[(vci_addr_t)(m_cmd_sc_addr_fifo.read())],
    43624752                                      0,
    43634753                                      0,
    43644754                                      0,
    4365                                       false,            // not a processor read
    4366                                       0,               
     4755                                      false,    // not a processor read
     4756                                      0,
    43674757                                      0,
    43684758                                      std::vector<be_t>(m_words,0),
     
    43714761                // invalidate directory entry
    43724762                DirectoryEntry entry;
    4373                 entry.valid             = false;
    4374                 entry.dirty             = false;
    4375                 entry.tag               = 0;
     4763                entry.valid         = false;
     4764                entry.dirty         = false;
     4765                entry.tag         = 0;
    43764766                entry.is_cnt        = false;
    4377                 entry.lock              = false;
     4767                entry.lock          = false;
    43784768                entry.count         = 0;
    43794769                entry.owner.srcid   = 0;
     
    43834773                entry.owner.inst    = false;
    43844774                entry.ptr           = 0;
    4385                 size_t set              = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
    4386                 size_t way              = r_sc_way.read();
     4775                size_t set          = m_y[(vci_addr_t)(m_cmd_sc_addr_fifo.read())];
     4776                size_t way          = r_sc_way.read();
    43874777                m_cache_directory.write(set, way, entry);
    43884778
     
    43974787}
    43984788#endif
    4399             } 
    4400             else 
     4789            }
     4790            else
    44014791            {
    44024792                assert(false and "LOCK ERROR in SC_FSM, STATE = SC_BC_DIR_INVAL");
     
    44084798        {
    44094799            if ( !r_sc_to_init_cmd_multi_req.read() &&
    4410                  !r_sc_to_init_cmd_brdcast_req.read()) 
     4800                 !r_sc_to_init_cmd_brdcast_req.read())
    44114801            {
    44124802                r_sc_to_init_cmd_multi_req    = false;
     
    44244814        case SC_BC_XRAM_REQ: // request the IXR FSM to start a put transaction
    44254815        {
    4426             if ( !r_sc_to_ixr_cmd_req ) 
     4816            if ( !r_sc_to_ixr_cmd_req )
    44274817            {
    44284818                r_sc_to_ixr_cmd_req     = true;
     
    44424832}
    44434833#endif
    4444             } 
    4445             else 
     4834            }
     4835            else
    44464836            {
    44474837               std::cout << "MEM_CACHE, SC_BC_XRAM_REQ state : request should not have been previously set"
     
    44534843        case SC_RSP_FAIL:  // request TGT_RSP FSM to send a failure response
    44544844        {
    4455             if( !r_sc_to_tgt_rsp_req ) 
    4456             {
    4457                 cmd_sc_fifo_get     = true;
     4845            if( !r_sc_to_tgt_rsp_req )
     4846            {
     4847                cmd_sc_fifo_get     = true;
    44584848                r_sc_cpt              = 0;
    4459                 r_sc_to_tgt_rsp_req     = true;
    4460                 r_sc_to_tgt_rsp_data    = 1;
    4461                 r_sc_to_tgt_rsp_srcid   = m_cmd_sc_srcid_fifo.read();
    4462                 r_sc_to_tgt_rsp_trdid   = m_cmd_sc_trdid_fifo.read();
    4463                 r_sc_to_tgt_rsp_pktid   = m_cmd_sc_pktid_fifo.read();
     4849                r_sc_to_tgt_rsp_req = true;
     4850                r_sc_to_tgt_rsp_data  = 1;
     4851                r_sc_to_tgt_rsp_srcid = m_cmd_sc_srcid_fifo.read();
     4852                r_sc_to_tgt_rsp_trdid = m_cmd_sc_trdid_fifo.read();
     4853                r_sc_to_tgt_rsp_pktid = m_cmd_sc_pktid_fifo.read();
    44644854                r_sc_fsm              = SC_IDLE;
    44654855
     
    44764866        case SC_RSP_SUCCESS:  // request TGT_RSP FSM to send a success response
    44774867        {
    4478             if( !r_sc_to_tgt_rsp_req ) 
     4868            if( !r_sc_to_tgt_rsp_req )
    44794869            {
    44804870                cmd_sc_fifo_get       = true;
    44814871                r_sc_cpt              = 0;
    4482                 r_sc_to_tgt_rsp_req     = true;
    4483                 r_sc_to_tgt_rsp_data    = 0;
    4484                 r_sc_to_tgt_rsp_srcid   = m_cmd_sc_srcid_fifo.read();
    4485                 r_sc_to_tgt_rsp_trdid   = m_cmd_sc_trdid_fifo.read();
    4486                 r_sc_to_tgt_rsp_pktid   = m_cmd_sc_pktid_fifo.read();
     4872                r_sc_to_tgt_rsp_req = true;
     4873                r_sc_to_tgt_rsp_data  = 0;
     4874                r_sc_to_tgt_rsp_srcid = m_cmd_sc_srcid_fifo.read();
     4875                r_sc_to_tgt_rsp_trdid = m_cmd_sc_trdid_fifo.read();
     4876                r_sc_to_tgt_rsp_pktid = m_cmd_sc_pktid_fifo.read();
    44874877                r_sc_fsm              = SC_IDLE;
    44884878
     
    44994889        case SC_MISS_TRT_LOCK:         // cache miss : request access to transaction Table
    45004890        {
    4501             if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC ) 
     4891            if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC )
    45024892            {
    45034893                size_t   index = 0;
     
    45114901if( m_debug_sc_fsm )
    45124902{
    4513     std::cout << "  <MEMC " << name() << ".SC_MISS_TRT_LOCK> Check TRT state" 
     4903    std::cout << "  <MEMC " << name() << ".SC_MISS_TRT_LOCK> Check TRT state"
    45144904              << " / hit_read = "  << hit_read
    45154905              << " / hit_write = " << hit_write
    4516               << " / wok = " << wok 
     4906              << " / wok = " << wok
    45174907              << " / index = " << index << std::endl;
    45184908}
     
    45224912                {
    45234913                    r_sc_fsm = SC_WAIT;
    4524                 } 
    4525                 else 
     4914                }
     4915                else
    45264916                {
    45274917                    r_sc_trt_index = index;
     
    45324922        }
    45334923        ////////////////////
    4534         case SC_MISS_TRT_SET:   // register the GET transaction in TRT
    4535         {
    4536             if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC ) 
     4924        case SC_MISS_TRT_SET: // register the GET transaction in TRT
     4925        {
     4926            if( r_alloc_trt_fsm.read() == ALLOC_TRT_SC )
    45374927            {
    45384928                std::vector<be_t> be_vector;
     
    45404930                be_vector.clear();
    45414931                data_vector.clear();
    4542                 for ( size_t i=0; i<m_words; i++ ) 
    4543                 {   
     4932                for ( size_t i=0; i<m_words; i++ )
     4933                {
    45444934                    be_vector.push_back(0);
    45454935                    data_vector.push_back(0);
     
    45474937
    45484938                m_transaction_tab.set(r_sc_trt_index.read(),
    4549                                       true,             // read request         
     4939                                      true,   // read request
    45504940                                      m_nline[(vci_addr_t)m_cmd_sc_addr_fifo.read()],
    45514941                                      m_cmd_sc_srcid_fifo.read(),
    45524942                                      m_cmd_sc_trdid_fifo.read(),
    45534943                                      m_cmd_sc_pktid_fifo.read(),
    4554                                       false,            // write request from processor
     4944                                      false,    // write request from processor
    45554945                                      0,
    45564946                                      0,
    45574947                                      be_vector,
    45584948                                      data_vector);
    4559                 r_sc_fsm = SC_MISS_XRAM_REQ;       
     4949                r_sc_fsm = SC_MISS_XRAM_REQ;
    45604950
    45614951#if DEBUG_MEMC_SC
     
    45634953{
    45644954    std::cout << "  <MEMC " << name() << ".SC_MISS_TRT_SET> Register a GET transaction in TRT" << std::hex
    4565               << " / nline = " << m_nline[(vci_addr_t)m_cmd_sc_addr_fifo.read()] 
     4955              << " / nline = " << m_nline[(vci_addr_t)m_cmd_sc_addr_fifo.read()]
    45664956              << " / trt_index = " << r_sc_trt_index.read() << std::endl;
    45674957}
     
    45714961        }
    45724962        //////////////////////
    4573         case SC_MISS_XRAM_REQ:  // request the IXR_CMD FSM to fetch the missing line
    4574         {
    4575             if ( !r_sc_to_ixr_cmd_req ) 
     4963        case SC_MISS_XRAM_REQ:  // request the IXR_CMD FSM to fetch the missing line
     4964        {
     4965            if ( !r_sc_to_ixr_cmd_req )
    45764966            {
    45774967                r_sc_to_ixr_cmd_req        = true;
     
    45964986
    45974987    //////////////////////////////////////////////////////////////////////////////
    4598     //          INIT_CMD FSM
     4988    //    INIT_CMD FSM
    45994989    //////////////////////////////////////////////////////////////////////////////
    46004990    // The INIT_CMD fsm controls the VCI CMD initiator port on the coherence
     
    46034993    // It implements a round-robin priority between the three possible client FSMs
    46044994    // XRAM_RSP, WRITE and SC. Each FSM can request two types of services:
    4605     // - r_xram_rsp_to_init_cmd_multi_req : multi-inval 
    4606     //   r_xram_rsp_to_init_cmd_brdcast_req : broadcast-inval 
    4607     // - r_write_to_init_cmd_multi_req : multi-update 
    4608     //   r_write_to_init_cmd_brdcast_req : broadcast-inval 
    4609     // - r_sc_to_init_cmd_multi_req : multi-update 
     4995    // - r_xram_rsp_to_init_cmd_multi_req : multi-inval
     4996    //   r_xram_rsp_to_init_cmd_brdcast_req : broadcast-inval
     4997    // - r_write_to_init_cmd_multi_req : multi-update
     4998    //   r_write_to_init_cmd_brdcast_req : broadcast-inval
     4999    // - r_sc_to_init_cmd_multi_req : multi-update
    46105000    //   r_sc_to_init_cmd_brdcast_req : broadcast-inval
    46115001    //
    4612     // An inval request is a single cell VCI write command containing the 
     5002    // An inval request is a single cell VCI write command containing the
    46135003    // index of the line to be invalidated.
    4614     // An update request is a multi-cells VCI write command : The first cell 
    4615     // contains the index of the cache line to be updated. The second cell contains 
     5004    // An update request is a multi-cells VCI write command : The first cell
     5005    // contains the index of the cache line to be updated. The second cell contains
    46165006    // the index of the first modified word in the line. The following cells
    46175007    // contain the data.
    46185008    ///////////////////////////////////////////////////////////////////////////////
    46195009
    4620     switch ( r_init_cmd_fsm.read() ) 
     5010    switch ( r_init_cmd_fsm.read() )
    46215011    {
    4622         //////////////////////// 
    4623         case INIT_CMD_UPDT_IDLE:        // XRAM_RSP FSM has highest priority
     5012        ////////////////////////
     5013        case INIT_CMD_UPDT_IDLE:  // XRAM_RSP FSM has highest priority
    46245014        {
    46255015            if ( m_xram_rsp_to_init_cmd_inst_fifo.rok() ||
    4626                  r_xram_rsp_to_init_cmd_multi_req.read()  ) 
     5016                 r_xram_rsp_to_init_cmd_multi_req.read()  )
    46275017            {
    46285018                r_init_cmd_fsm = INIT_CMD_INVAL_NLINE;
    46295019                m_cpt_inval++;
    4630             } 
    4631             else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() ) 
     5020            }
     5021            else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() )
    46325022            {
    46335023                r_init_cmd_fsm = INIT_CMD_XRAM_BRDCAST;
    46345024                m_cpt_inval++;
    4635             } 
     5025            }
    46365026            else if ( m_write_to_init_cmd_inst_fifo.rok() ||
    4637                       r_write_to_init_cmd_multi_req.read() ) 
     5027                      r_write_to_init_cmd_multi_req.read() )
    46385028            {
    46395029                r_init_cmd_fsm = INIT_CMD_UPDT_NLINE;
    46405030                m_cpt_update++;
    4641             } 
     5031            }
    46425032            else if ( r_write_to_init_cmd_brdcast_req.read() )
    46435033            {
    46445034                r_init_cmd_fsm = INIT_CMD_WRITE_BRDCAST;
    46455035                m_cpt_inval++;
    4646             } 
     5036            }
    46475037            else if ( m_sc_to_init_cmd_inst_fifo.rok() ||
    4648                       r_sc_to_init_cmd_multi_req.read()  ) 
     5038                      r_sc_to_init_cmd_multi_req.read()  )
    46495039            {
    46505040                r_init_cmd_fsm = INIT_CMD_SC_UPDT_NLINE;
    46515041                m_cpt_update++;
    4652             } 
     5042            }
    46535043            else if( r_sc_to_init_cmd_brdcast_req.read() )
    46545044            {
     
    46595049        }
    46605050        /////////////////////////
    4661         case INIT_CMD_INVAL_IDLE:       // WRITE FSM has highest priority
     5051        case INIT_CMD_INVAL_IDLE: // WRITE FSM has highest priority
    46625052        {
    46635053            if ( m_write_to_init_cmd_inst_fifo.rok() ||
    4664                  r_write_to_init_cmd_multi_req.read() ) 
     5054                 r_write_to_init_cmd_multi_req.read() )
    46655055            {
    46665056                r_init_cmd_fsm = INIT_CMD_UPDT_NLINE;
    46675057                m_cpt_update++;
    4668             } 
     5058            }
    46695059            else if ( r_write_to_init_cmd_brdcast_req.read() )
    46705060            {
    46715061                r_init_cmd_fsm = INIT_CMD_WRITE_BRDCAST;
    46725062                m_cpt_inval++;
    4673             } 
     5063            }
    46745064            else if ( m_sc_to_init_cmd_inst_fifo.rok() ||
    4675                       r_sc_to_init_cmd_multi_req.read()  ) 
     5065                      r_sc_to_init_cmd_multi_req.read()  )
    46765066            {
    46775067                r_init_cmd_fsm = INIT_CMD_SC_UPDT_NLINE;
    46785068                m_cpt_update++;
    4679             } 
     5069            }
    46805070            else if( r_sc_to_init_cmd_brdcast_req.read() )
    46815071            {
    46825072                r_init_cmd_fsm = INIT_CMD_SC_BRDCAST;
    46835073                m_cpt_inval++;
    4684             } 
     5074            }
    46855075            else if ( m_xram_rsp_to_init_cmd_inst_fifo.rok() ||
    4686                       r_xram_rsp_to_init_cmd_multi_req.read()  ) 
     5076                      r_xram_rsp_to_init_cmd_multi_req.read()  )
    46875077            {
    46885078                r_init_cmd_fsm = INIT_CMD_INVAL_NLINE;
    46895079                m_cpt_inval++;
    4690             } 
    4691             else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() ) 
     5080            }
     5081            else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() )
    46925082            {
    46935083                r_init_cmd_fsm = INIT_CMD_XRAM_BRDCAST;
     
    46975087        }
    46985088        //////////////////////////
    4699         case INIT_CMD_SC_UPDT_IDLE:     // SC FSM has highest priority
     5089        case INIT_CMD_SC_UPDT_IDLE: // SC FSM has highest priority
    47005090        {
    47015091            if ( m_sc_to_init_cmd_inst_fifo.rok() ||
    4702                  r_sc_to_init_cmd_multi_req.read()  ) 
     5092                 r_sc_to_init_cmd_multi_req.read()  )
    47035093            {
    47045094                r_init_cmd_fsm = INIT_CMD_SC_UPDT_NLINE;
    47055095                m_cpt_update++;
    4706             } 
     5096            }
    47075097            else if( r_sc_to_init_cmd_brdcast_req.read() )
    47085098            {
    47095099                r_init_cmd_fsm = INIT_CMD_SC_BRDCAST;
    47105100                m_cpt_inval++;
    4711             } 
     5101            }
    47125102            else if ( m_xram_rsp_to_init_cmd_inst_fifo.rok() ||
    4713                       r_xram_rsp_to_init_cmd_multi_req.read()  ) 
     5103                      r_xram_rsp_to_init_cmd_multi_req.read()  )
    47145104            {
    47155105                r_init_cmd_fsm = INIT_CMD_INVAL_NLINE;
    47165106                m_cpt_inval++;
    4717             } 
    4718             else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() ) 
     5107            }
     5108            else if ( r_xram_rsp_to_init_cmd_brdcast_req.read() )
    47195109            {
    47205110                r_init_cmd_fsm = INIT_CMD_XRAM_BRDCAST;
    47215111                m_cpt_inval++;
    4722             } 
     5112            }
    47235113            else if ( m_write_to_init_cmd_inst_fifo.rok() ||
    4724                       r_write_to_init_cmd_multi_req.read() ) 
     5114                      r_write_to_init_cmd_multi_req.read() )
    47255115            {
    47265116                r_init_cmd_fsm = INIT_CMD_UPDT_NLINE;
    47275117                m_cpt_update++;
    4728             } 
     5118            }
    47295119            else if ( r_write_to_init_cmd_brdcast_req.read() )
    47305120            {
     
    47355125        }
    47365126        //////////////////////////
    4737         case INIT_CMD_INVAL_NLINE:      // send a multi-inval (from XRAM_RSP)
     5127        case INIT_CMD_INVAL_NLINE:  // send a multi-inval (from XRAM_RSP)
    47385128        {
    47395129            if ( m_xram_rsp_to_init_cmd_inst_fifo.rok() )
    47405130            {
    4741                 if ( p_vci_ini.cmdack ) 
     5131                if ( p_vci_ini.cmdack )
    47425132                {
    47435133                    m_cpt_inval_mult++;
     
    47455135                    xram_rsp_to_init_cmd_fifo_get = true;
    47465136                }
    4747             } 
    4748             else 
     5137            }
     5138            else
    47495139            {
    47505140                if( r_xram_rsp_to_init_cmd_multi_req.read() ) r_xram_rsp_to_init_cmd_multi_req = false;
     
    47545144        }
    47555145        ///////////////////////////
    4756         case INIT_CMD_XRAM_BRDCAST:     // send a broadcast-inval (from XRAM_RSP)
    4757         {
    4758             if ( p_vci_ini.cmdack ) 
     5146        case INIT_CMD_XRAM_BRDCAST: // send a broadcast-inval (from XRAM_RSP)
     5147        {
     5148            if ( p_vci_ini.cmdack )
    47595149            {
    47605150                m_cpt_inval_brdcast++;
     
    47655155        }
    47665156        ////////////////////////////
    4767         case INIT_CMD_WRITE_BRDCAST:    // send a broadcast-inval (from WRITE FSM)
    4768         {
    4769             if( p_vci_ini.cmdack ) 
     5157        case INIT_CMD_WRITE_BRDCAST:  // send a broadcast-inval (from WRITE FSM)
     5158        {
     5159            if( p_vci_ini.cmdack )
    47705160            {
    47715161
     
    47735163if( m_debug_init_cmd_fsm )
    47745164{
    4775     std::cout << "  <MEMC " << name() << ".INIT_CMD_WRITE_BRDCAST> Broadcast-Inval for line " 
     5165    std::cout << "  <MEMC " << name() << ".INIT_CMD_WRITE_BRDCAST> Broadcast-Inval for line "
    47765166              << r_write_to_init_cmd_nline.read() << std::endl;
    47775167}
     
    47865176        case INIT_CMD_UPDT_NLINE:  // send nline for a multi-update (from WRITE FSM)
    47875177        {
    4788             if ( m_write_to_init_cmd_inst_fifo.rok() ) 
     5178            if ( m_write_to_init_cmd_inst_fifo.rok() )
    47895179            {
    47905180                if ( p_vci_ini.cmdack )
     
    47945184                    // write_to_init_cmd_fifo_get = true;
    47955185                }
    4796             } 
    4797             else 
     5186            }
     5187            else
    47985188            {
    47995189                if ( r_write_to_init_cmd_multi_req.read() ) r_write_to_init_cmd_multi_req = false;
     
    48125202        case INIT_CMD_UPDT_DATA:  // send the data for a multi-update (from WRITE FSM)
    48135203        {
    4814             if ( p_vci_ini.cmdack ) 
    4815             {
    4816                 if ( r_init_cmd_cpt.read() == (r_write_to_init_cmd_count.read()-1) ) 
     5204            if ( p_vci_ini.cmdack )
     5205            {
     5206                if ( r_init_cmd_cpt.read() == (r_write_to_init_cmd_count.read()-1) )
    48175207                {
    48185208                    r_init_cmd_fsm = INIT_CMD_UPDT_NLINE;
    48195209                    write_to_init_cmd_fifo_get = true;
    4820                 } 
    4821                 else 
     5210                }
     5211                else
    48225212                {
    48235213                    r_init_cmd_cpt = r_init_cmd_cpt.read() + 1;
     
    48275217        }
    48285218        /////////////////////////
    4829         case INIT_CMD_SC_BRDCAST:       // send a broadcast-inval (from SC FSM)
    4830         {
    4831             if( p_vci_ini.cmdack ) 
     5219        case INIT_CMD_SC_BRDCAST: // send a broadcast-inval (from SC FSM)
     5220        {
     5221            if( p_vci_ini.cmdack )
    48325222            {
    48335223                m_cpt_inval_brdcast++;
     
    48475237                    r_init_cmd_fsm = INIT_CMD_SC_UPDT_INDEX;
    48485238                }
    4849             } 
    4850             else 
     5239            }
     5240            else
    48515241            {
    48525242                if( r_sc_to_init_cmd_multi_req.read() ) r_sc_to_init_cmd_multi_req = false;
     
    48625252        }
    48635253        ///////////////////////////
    4864         case INIT_CMD_SC_UPDT_DATA:  // send first data for a multi-update (from SC FSM) 
    4865         {
    4866             if ( p_vci_ini.cmdack ) 
     5254        case INIT_CMD_SC_UPDT_DATA:  // send first data for a multi-update (from SC FSM)
     5255        {
     5256            if ( p_vci_ini.cmdack )
    48675257            {
    48685258                if ( r_sc_to_init_cmd_is_long.read() )
    48695259                {
    48705260                    r_init_cmd_fsm = INIT_CMD_SC_UPDT_DATA_HIGH;
    4871                 } 
    4872                 else 
     5261                }
     5262                else
    48735263                {
    48745264                    sc_to_init_cmd_fifo_get = true;
     
    48815271        case INIT_CMD_SC_UPDT_DATA_HIGH:  // send second data for a multi-update (from SC FSM)
    48825272        {
    4883             if ( p_vci_ini.cmdack ) 
     5273            if ( p_vci_ini.cmdack )
    48845274            {
    48855275                sc_to_init_cmd_fifo_get = true;
     
    48915281
    48925282    /////////////////////////////////////////////////////////////////////
    4893     //          TGT_RSP FSM
     5283    //    TGT_RSP FSM
    48945284    /////////////////////////////////////////////////////////////////////
    48955285    // The TGT_RSP fsm sends the responses on the VCI target port
     
    49045294    /////////////////////////////////////////////////////////////////////
    49055295
    4906     switch ( r_tgt_rsp_fsm.read() ) 
     5296    switch ( r_tgt_rsp_fsm.read() )
    49075297    {
    49085298        ///////////////////////
    4909         case TGT_RSP_READ_IDLE:         // write requests have the highest priority
     5299        case TGT_RSP_READ_IDLE:   // write requests have the highest priority
    49105300        {
    49115301          if      ( r_write_to_tgt_rsp_req    ) r_tgt_rsp_fsm = TGT_RSP_WRITE;
    49125302          else if ( r_sc_to_tgt_rsp_req     ) r_tgt_rsp_fsm = TGT_RSP_SC;
    4913           else if ( r_xram_rsp_to_tgt_rsp_req ) 
     5303          else if ( r_xram_rsp_to_tgt_rsp_req )
    49145304          {
    49155305            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    49185308          else if ( r_init_rsp_to_tgt_rsp_req ) r_tgt_rsp_fsm = TGT_RSP_INIT;
    49195309          else if ( r_cleanup_to_tgt_rsp_req  ) r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
    4920           else if ( r_read_to_tgt_rsp_req     ) 
     5310          else if ( r_read_to_tgt_rsp_req     )
    49215311          {
    49225312            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    49265316        }
    49275317        ////////////////////////
    4928         case TGT_RSP_WRITE_IDLE:        // sc requests have the highest priority
     5318        case TGT_RSP_WRITE_IDLE:  // sc requests have the highest priority
    49295319        {
    49305320          if      ( r_sc_to_tgt_rsp_req     ) r_tgt_rsp_fsm = TGT_RSP_SC;
    4931           else if ( r_xram_rsp_to_tgt_rsp_req ) 
     5321          else if ( r_xram_rsp_to_tgt_rsp_req )
    49325322          {
    49335323            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    49365326          else if ( r_init_rsp_to_tgt_rsp_req ) r_tgt_rsp_fsm = TGT_RSP_INIT;
    49375327          else if ( r_cleanup_to_tgt_rsp_req  ) r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
    4938           else if ( r_read_to_tgt_rsp_req     ) 
     5328          else if ( r_read_to_tgt_rsp_req     )
    49395329          {
    49405330            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    49465336        }
    49475337        ///////////////////////
    4948         case TGT_RSP_SC_IDLE:           // xram_rsp requests have the highest priority
    4949         {
    4950           if ( r_xram_rsp_to_tgt_rsp_req ) 
     5338        case TGT_RSP_SC_IDLE:   // xram_rsp requests have the highest priority
     5339        {
     5340          if ( r_xram_rsp_to_tgt_rsp_req )
    49515341          {
    49525342            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    49555345          else if ( r_init_rsp_to_tgt_rsp_req ) r_tgt_rsp_fsm = TGT_RSP_INIT;
    49565346          else if ( r_cleanup_to_tgt_rsp_req  ) r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
    4957           else if ( r_read_to_tgt_rsp_req     ) 
     5347          else if ( r_read_to_tgt_rsp_req     )
    49585348          {
    49595349            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    49655355        }
    49665356        ///////////////////////
    4967         case TGT_RSP_XRAM_IDLE:         // init requests have the highest priority
     5357        case TGT_RSP_XRAM_IDLE:   // init requests have the highest priority
    49685358        {
    49695359
    49705360          if      ( r_init_rsp_to_tgt_rsp_req ) r_tgt_rsp_fsm = TGT_RSP_INIT;
    49715361          else if ( r_cleanup_to_tgt_rsp_req  ) r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
    4972           else if ( r_read_to_tgt_rsp_req     ) 
     5362          else if ( r_read_to_tgt_rsp_req     )
    49735363          {
    49745364            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    49775367          else if ( r_write_to_tgt_rsp_req    ) r_tgt_rsp_fsm = TGT_RSP_WRITE;
    49785368          else if ( r_sc_to_tgt_rsp_req     ) r_tgt_rsp_fsm = TGT_RSP_SC;
    4979           else if ( r_xram_rsp_to_tgt_rsp_req ) 
     5369          else if ( r_xram_rsp_to_tgt_rsp_req )
    49805370          {
    49815371            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    49855375        }
    49865376        ///////////////////////
    4987         case TGT_RSP_INIT_IDLE:         // cleanup requests have the highest priority
     5377        case TGT_RSP_INIT_IDLE:   // cleanup requests have the highest priority
    49885378        {
    49895379          if      ( r_cleanup_to_tgt_rsp_req  ) r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
    4990           else if ( r_read_to_tgt_rsp_req     ) 
     5380          else if ( r_read_to_tgt_rsp_req     )
    49915381          {
    49925382            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    49955385          else if ( r_write_to_tgt_rsp_req    ) r_tgt_rsp_fsm = TGT_RSP_WRITE;
    49965386          else if ( r_sc_to_tgt_rsp_req     ) r_tgt_rsp_fsm = TGT_RSP_SC;
    4997           else if ( r_xram_rsp_to_tgt_rsp_req ) 
     5387          else if ( r_xram_rsp_to_tgt_rsp_req )
    49985388          {
    49995389            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    50045394        }
    50055395        ///////////////////////
    5006         case TGT_RSP_CLEANUP_IDLE:              // read requests have the highest priority
    5007         {
    5008           if      ( r_read_to_tgt_rsp_req     ) 
     5396        case TGT_RSP_CLEANUP_IDLE:    // read requests have the highest priority
     5397        {
     5398          if      ( r_read_to_tgt_rsp_req     )
    50095399          {
    50105400            r_tgt_rsp_fsm = TGT_RSP_READ;
     
    50135403          else if ( r_write_to_tgt_rsp_req    ) r_tgt_rsp_fsm = TGT_RSP_WRITE;
    50145404          else if ( r_sc_to_tgt_rsp_req     ) r_tgt_rsp_fsm = TGT_RSP_SC;
    5015           else if ( r_xram_rsp_to_tgt_rsp_req ) 
     5405          else if ( r_xram_rsp_to_tgt_rsp_req )
    50165406          {
    50175407            r_tgt_rsp_fsm = TGT_RSP_XRAM;
     
    50235413        }
    50245414        //////////////////
    5025         case TGT_RSP_READ:              // send the response to a read
    5026         {
    5027             if ( p_vci_tgt.rspack ) 
     5415        case TGT_RSP_READ:    // send the response to a read
     5416        {
     5417            if ( p_vci_tgt.rspack )
    50285418            {
    50295419
     
    50385428}
    50395429#endif
    5040                 if ( r_tgt_rsp_cpt.read() == (r_read_to_tgt_rsp_word.read()+r_read_to_tgt_rsp_length-1) ) 
     5430                if ( r_tgt_rsp_cpt.read() == (r_read_to_tgt_rsp_word.read()+r_read_to_tgt_rsp_length-1) )
    50415431                {
    50425432                    r_tgt_rsp_fsm = TGT_RSP_READ_IDLE;
    50435433                    r_read_to_tgt_rsp_req = false;
    5044                 } 
    5045                 else 
     5434                }
     5435                else
    50465436                {
    50475437                    r_tgt_rsp_cpt = r_tgt_rsp_cpt.read() + 1;
     
    50515441        }
    50525442        ///////////////////
    5053         case TGT_RSP_WRITE:             // send the write acknowledge
    5054         {
    5055             if ( p_vci_tgt.rspack ) 
     5443        case TGT_RSP_WRITE:   // send the write acknowledge
     5444        {
     5445            if ( p_vci_tgt.rspack )
    50565446            {
    50575447
     
    50705460        }
    50715461        ///////////////////
    5072         case TGT_RSP_CLEANUP:           // pas clair pour moi (AG)   
    5073         {
    5074             if ( p_vci_tgt.rspack ) 
     5462        case TGT_RSP_CLEANUP:   // pas clair pour moi (AG)
     5463        {
     5464            if ( p_vci_tgt.rspack )
    50755465            {
    50765466
     
    50895479        }
    50905480        //////////////////
    5091         case TGT_RSP_SC:                // send one atomic word response
    5092         {
    5093             if ( p_vci_tgt.rspack ) 
     5481        case TGT_RSP_SC:    // send one atomic word response
     5482        {
     5483            if ( p_vci_tgt.rspack )
    50945484            {
    50955485
     
    51095499
    51105500        ///////////////////////
    5111         case TGT_RSP_XRAM:              // send the response after XRAM access
    5112         {
    5113             if ( p_vci_tgt.rspack ) 
     5501        case TGT_RSP_XRAM:    // send the response after XRAM access
     5502        {
     5503            if ( p_vci_tgt.rspack )
    51145504            {
    51155505
     
    51245514}
    51255515#endif
    5126                 if ( (r_tgt_rsp_cpt.read() == 
     5516                if ( (r_tgt_rsp_cpt.read() ==
    51275517                     (r_xram_rsp_to_tgt_rsp_word.read()+r_xram_rsp_to_tgt_rsp_length.read()-1))
    5128                    || r_xram_rsp_to_tgt_rsp_rerror.read() ) 
     5518                   || r_xram_rsp_to_tgt_rsp_rerror.read() )
    51295519                {
    51305520                    r_tgt_rsp_fsm = TGT_RSP_XRAM_IDLE;
    51315521                    r_xram_rsp_to_tgt_rsp_req = false;
    5132                 } 
    5133                 else 
     5522                }
     5523                else
    51345524                {
    51355525                    r_tgt_rsp_cpt = r_tgt_rsp_cpt.read() + 1;
     
    51395529        }
    51405530        //////////////////
    5141         case TGT_RSP_INIT:              // send the write response after coherence transaction
    5142         {
    5143             if ( p_vci_tgt.rspack ) 
     5531        case TGT_RSP_INIT:    // send the write response after coherence transaction
     5532        {
     5533            if ( p_vci_tgt.rspack )
    51445534            {
    51455535
     
    51605550
    51615551    ////////////////////////////////////////////////////////////////////////////////////
    5162     //          ALLOC_UPT FSM
     5552    //    ALLOC_UPT FSM
    51635553    ////////////////////////////////////////////////////////////////////////////////////
    51645554    // The ALLOC_UPT FSM allocates the access to the Update/Inval Table (UPT).
    5165     // with a round robin priority between three FSMs : INIT_RSP > WRITE > XRAM_RSP > CLEANUP 
     5555    // with a round robin priority between three FSMs : INIT_RSP > WRITE > XRAM_RSP > CLEANUP
    51665556    // - The WRITE FSM initiates update transactions and sets  new entry in UPT.
    51675557    // - The XRAM_RSP FSM initiates inval transactions and sets  new entry in UPT.
     
    51715561    /////////////////////////////////////////////////////////////////////////////////////
    51725562
    5173     switch ( r_alloc_upt_fsm.read() ) 
     5563    switch ( r_alloc_upt_fsm.read() )
    51745564    {
    51755565
    51765566      ////////////////////////
    51775567      case ALLOC_UPT_INIT_RSP:
    5178         if ( (r_init_rsp_fsm.read() != INIT_RSP_UPT_LOCK) &&
    5179              (r_init_rsp_fsm.read() != INIT_RSP_UPT_CLEAR) )
    5180         {
    5181           if      ((r_write_fsm.read() == WRITE_UPT_LOCK) ||
    5182                    (r_write_fsm.read() == WRITE_BC_UPT_LOCK))        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
    5183           else if (r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK)    r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
    5184           else if (r_cleanup_fsm.read() == CLEANUP_UPT_LOCK)        r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
    5185           else if ((r_sc_fsm.read() == SC_UPT_LOCK) ||
    5186                    (r_sc_fsm.read() == SC_BC_UPT_LOCK))            r_alloc_upt_fsm = ALLOC_UPT_SC;
     5568        if (( r_init_rsp_fsm.read() != INIT_RSP_UPT_LOCK  ) &&
     5569            ( r_init_rsp_fsm.read() != INIT_RSP_UPT_CLEAR ))
     5570        {
     5571          if (( r_write_fsm.read() == WRITE_UPT_LOCK    ) ||
     5572              ( r_write_fsm.read() == WRITE_BC_UPT_LOCK ))
     5573            r_alloc_upt_fsm = ALLOC_UPT_WRITE;
     5574
     5575          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK )
     5576            r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
     5577
     5578          else if ( r_cleanup_fsm.read() == CLEANUP_UPT_LOCK )
     5579            r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
     5580
     5581          else if (( r_sc_fsm.read() == SC_UPT_LOCK    ) ||
     5582                   ( r_sc_fsm.read() == SC_BC_UPT_LOCK ))
     5583            r_alloc_upt_fsm = ALLOC_UPT_SC;
    51875584        }
    51885585        break;
     
    51905587        /////////////////////
    51915588      case ALLOC_UPT_WRITE:
    5192         if ( (r_write_fsm.read() != WRITE_UPT_LOCK) &&
    5193              (r_write_fsm.read() != WRITE_BC_UPT_LOCK))
    5194         {
    5195           if      (r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK)    r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
    5196           else if (r_cleanup_fsm.read() == CLEANUP_UPT_LOCK)        r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
    5197           else if ((r_sc_fsm.read() == SC_UPT_LOCK) ||
    5198                    (r_sc_fsm.read() == SC_BC_UPT_LOCK))            r_alloc_upt_fsm = ALLOC_UPT_SC;
    5199           else if (r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK)      r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
     5589        if (( r_write_fsm.read() != WRITE_UPT_LOCK    ) &&
     5590            ( r_write_fsm.read() != WRITE_BC_UPT_LOCK ))
     5591        {
     5592          if ( r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK )
     5593            r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
     5594
     5595          else if ( r_cleanup_fsm.read() == CLEANUP_UPT_LOCK )
     5596            r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
     5597
     5598          else if (( r_sc_fsm.read() == SC_UPT_LOCK    ) ||
     5599                   ( r_sc_fsm.read() == SC_BC_UPT_LOCK ))
     5600            r_alloc_upt_fsm = ALLOC_UPT_SC;
     5601
     5602          else if ( r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK )
     5603            r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
    52005604        }
    52015605        break;
     
    52035607        ////////////////////////
    52045608      case ALLOC_UPT_XRAM_RSP:
    5205         if (r_xram_rsp_fsm.read() != XRAM_RSP_INVAL_LOCK)
    5206         {
    5207           if       (r_cleanup_fsm.read() == CLEANUP_UPT_LOCK)       r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
    5208           else if ((r_sc_fsm.read() == SC_UPT_LOCK) ||
    5209                    (r_sc_fsm.read() == SC_BC_UPT_LOCK))            r_alloc_upt_fsm = ALLOC_UPT_SC;
    5210           else if  (r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK)     r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
    5211           else if ((r_write_fsm.read() == WRITE_UPT_LOCK)   ||
    5212                    (r_write_fsm.read() == WRITE_BC_UPT_LOCK))        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
     5609        if (r_xram_rsp_fsm.read() != XRAM_RSP_INVAL_LOCK)
     5610        {
     5611          if ( r_cleanup_fsm.read() == CLEANUP_UPT_LOCK )
     5612            r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
     5613
     5614          else if (( r_sc_fsm.read() == SC_UPT_LOCK    ) ||
     5615                   ( r_sc_fsm.read() == SC_BC_UPT_LOCK ))
     5616            r_alloc_upt_fsm = ALLOC_UPT_SC;
     5617
     5618          else if ( r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK )
     5619            r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
     5620
     5621          else if (( r_write_fsm.read() == WRITE_UPT_LOCK    )   ||
     5622                   ( r_write_fsm.read() == WRITE_BC_UPT_LOCK ))
     5623            r_alloc_upt_fsm = ALLOC_UPT_WRITE;
    52135624        }
    52145625        break;
     
    52185629        if(r_cleanup_fsm.read() != CLEANUP_UPT_LOCK )
    52195630        {
    5220           if      ((r_sc_fsm.read() == SC_UPT_LOCK) ||
    5221                    (r_sc_fsm.read() == SC_BC_UPT_LOCK))            r_alloc_upt_fsm = ALLOC_UPT_SC;
    5222           else if  (r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK)     r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
    5223           else if ((r_write_fsm.read() == WRITE_UPT_LOCK) ||
    5224                    (r_write_fsm.read() == WRITE_BC_UPT_LOCK))        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
    5225           else if (r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK)    r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
     5631          if (( r_sc_fsm.read() == SC_UPT_LOCK    ) ||
     5632              ( r_sc_fsm.read() == SC_BC_UPT_LOCK ))
     5633            r_alloc_upt_fsm = ALLOC_UPT_SC;
     5634
     5635          else if ( r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK )
     5636            r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
     5637
     5638          else if (( r_write_fsm.read() == WRITE_UPT_LOCK    ) ||
     5639                   ( r_write_fsm.read() == WRITE_BC_UPT_LOCK ))
     5640            r_alloc_upt_fsm = ALLOC_UPT_WRITE;
     5641
     5642          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK )
     5643            r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
    52265644        }
    52275645        break;
    5228        
     5646
    52295647        //////////////////////////
    52305648      case ALLOC_UPT_SC:
    5231         if( (r_sc_fsm.read() != SC_UPT_LOCK) &&
    5232             (r_sc_fsm.read() != SC_BC_UPT_LOCK))
    5233         {
    5234           if      (r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK)      r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
    5235           else if ((r_write_fsm.read() == WRITE_UPT_LOCK) ||
    5236                    (r_write_fsm.read() == WRITE_BC_UPT_LOCK))        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
    5237           else if (r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK)    r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
    5238           else if (r_cleanup_fsm.read() == CLEANUP_UPT_LOCK)        r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
     5649        if (( r_sc_fsm.read() != SC_UPT_LOCK    ) &&
     5650            ( r_sc_fsm.read() != SC_BC_UPT_LOCK ))
     5651        {
     5652          if ( r_init_rsp_fsm.read() == INIT_RSP_UPT_LOCK )
     5653            r_alloc_upt_fsm = ALLOC_UPT_INIT_RSP;
     5654
     5655          else if (( r_write_fsm.read() == WRITE_UPT_LOCK    ) ||
     5656                   ( r_write_fsm.read() == WRITE_BC_UPT_LOCK ))
     5657            r_alloc_upt_fsm = ALLOC_UPT_WRITE;
     5658
     5659          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_INVAL_LOCK )
     5660            r_alloc_upt_fsm = ALLOC_UPT_XRAM_RSP;
     5661
     5662          else if ( r_cleanup_fsm.read() == CLEANUP_UPT_LOCK )
     5663            r_alloc_upt_fsm = ALLOC_UPT_CLEANUP;
    52395664        }
    52405665        break;
     
    52435668
    52445669    ////////////////////////////////////////////////////////////////////////////////////
    5245     //          ALLOC_DIR FSM
     5670    //    ALLOC_DIR FSM
    52465671    ////////////////////////////////////////////////////////////////////////////////////
    52475672    // The ALLOC_DIR FSM allocates the access to the directory and
     
    52515676    /////////////////////////////////////////////////////////////////////////////////////
    52525677
    5253     switch ( r_alloc_dir_fsm.read() ) 
     5678    switch ( r_alloc_dir_fsm.read() )
    52545679    {
     5680      case ALLOC_DIR_RESET:
     5681        // Initializes the directory one SET each cycle. All the WAYS of a SET are
     5682        // initialize in parallel
     5683
     5684        r_alloc_dir_reset_cpt.write(r_alloc_dir_reset_cpt.read() + 1);
     5685
     5686        if (r_alloc_dir_reset_cpt.read() == (m_sets - 1)) {
     5687          m_cache_directory.init();
     5688
     5689          r_alloc_dir_fsm = ALLOC_DIR_READ;
     5690        }
     5691        break;
     5692
    52555693      ////////////////////
    52565694      case ALLOC_DIR_READ:
    5257         if ( ( (r_read_fsm.read() != READ_DIR_LOCK) &&
    5258               (r_read_fsm.read() != READ_TRT_LOCK)  &&
    5259               (r_read_fsm.read() != READ_HEAP_LOCK))
     5695        if ((( r_read_fsm.read()       != READ_DIR_REQ    )   &&
     5696             ( r_read_fsm.read()       != READ_DIR_LOCK   )   &&
     5697             ( r_read_fsm.read()       != READ_TRT_LOCK   )   &&
     5698             ( r_read_fsm.read()       != READ_HEAP_REQ   ))
    52605699            ||
    5261             ( (r_read_fsm.read()        == READ_HEAP_LOCK) &&
    5262               (r_alloc_heap_fsm.read()  == ALLOC_HEAP_READ) )
     5700            (( r_read_fsm.read()       == READ_HEAP_REQ   )  &&
     5701             ( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ ))
    52635702            ||
    5264             ( (r_read_fsm.read()      == READ_TRT_LOCK)  &&
    5265               (r_alloc_trt_fsm.read() == ALLOC_TRT_READ)    )  )
    5266         {
    5267           if        (r_write_fsm.read() == WRITE_DIR_LOCK)          r_alloc_dir_fsm = ALLOC_DIR_WRITE;
    5268           else if   (r_sc_fsm.read() == SC_DIR_LOCK)              r_alloc_dir_fsm = ALLOC_DIR_SC;
    5269           else if   (r_cleanup_fsm.read() == CLEANUP_DIR_LOCK)      r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
    5270           else if   (r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)    r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
     5703            (( r_read_fsm.read()       == READ_TRT_LOCK   )   &&
     5704             ( r_alloc_trt_fsm.read()  == ALLOC_TRT_READ  )))
     5705        {
     5706          if (r_write_fsm.read() == WRITE_DIR_REQ)
     5707            r_alloc_dir_fsm = ALLOC_DIR_WRITE;
     5708
     5709          else if (r_sc_fsm.read() == SC_DIR_REQ)
     5710            r_alloc_dir_fsm = ALLOC_DIR_SC;
     5711
     5712          else if (r_cleanup_fsm.read() == CLEANUP_DIR_REQ )
     5713            r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
     5714
     5715          else if (r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
     5716            r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
    52715717        }
    52725718        break;
     
    52745720        /////////////////////
    52755721      case ALLOC_DIR_WRITE:
    5276         if ( ((r_write_fsm.read() != WRITE_DIR_LOCK) &&
    5277               (r_write_fsm.read() != WRITE_MISS_TRT_LOCK) &&
    5278               (r_write_fsm.read() != WRITE_DIR_READ) &&
    5279               (r_write_fsm.read() != WRITE_DIR_HIT) &&
    5280               (r_write_fsm.read() != WRITE_BC_TRT_LOCK) &&
    5281               (r_write_fsm.read() != WRITE_BC_UPT_LOCK) &&
    5282               (r_write_fsm.read() != WRITE_UPT_LOCK) &&
    5283               (r_write_fsm.read() != WRITE_UPT_HEAP_LOCK))
     5722        if ((( r_write_fsm.read()      != WRITE_DIR_REQ       )  &&
     5723             ( r_write_fsm.read()      != WRITE_DIR_LOCK      )  &&
     5724             ( r_write_fsm.read()      != WRITE_DIR_READ      )  &&
     5725             ( r_write_fsm.read()      != WRITE_DIR_HIT       )  &&
     5726             ( r_write_fsm.read()      != WRITE_BC_TRT_LOCK   )  &&
     5727             ( r_write_fsm.read()      != WRITE_BC_UPT_LOCK   )  &&
     5728             ( r_write_fsm.read()      != WRITE_MISS_TRT_LOCK )  &&
     5729             ( r_write_fsm.read()      != WRITE_UPT_LOCK      )  &&
     5730             ( r_write_fsm.read()      != WRITE_UPT_HEAP_LOCK ))
    52845731            ||
    5285             ( (r_write_fsm.read()       == WRITE_UPT_HEAP_LOCK) &&
    5286               (r_alloc_heap_fsm.read()  == ALLOC_HEAP_WRITE) )
     5732            (( r_write_fsm.read()      == WRITE_UPT_HEAP_LOCK ) &&
     5733             ( r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE    ))
    52875734            ||
    5288             ( (r_write_fsm.read()     == WRITE_MISS_TRT_LOCK) &&
    5289               (r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE)   )   )
    5290         {
    5291           if        (r_sc_fsm.read() == SC_DIR_LOCK)              r_alloc_dir_fsm = ALLOC_DIR_SC;
    5292           else if   (r_cleanup_fsm.read() == CLEANUP_DIR_LOCK)      r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
    5293           else if   (r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)    r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
    5294           else if   (r_read_fsm.read() == READ_DIR_LOCK)                r_alloc_dir_fsm = ALLOC_DIR_READ;
     5735            (( r_write_fsm.read()      == WRITE_MISS_TRT_LOCK )  &&
     5736             ( r_alloc_trt_fsm.read()  == ALLOC_TRT_WRITE     )))
     5737        {
     5738          if ( r_sc_fsm.read() == SC_DIR_REQ )
     5739            r_alloc_dir_fsm = ALLOC_DIR_SC;
     5740
     5741          else if ( r_cleanup_fsm.read() == CLEANUP_DIR_REQ )
     5742            r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
     5743
     5744          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK )
     5745            r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
     5746
     5747          else if ( r_read_fsm.read() == READ_DIR_REQ )
     5748            r_alloc_dir_fsm = ALLOC_DIR_READ;
    52955749        }
    52965750        break;
     
    52985752        ////////////////////
    52995753        case ALLOC_DIR_SC:
    5300         if ( ((r_sc_fsm.read() != SC_DIR_LOCK)       &&
    5301               (r_sc_fsm.read() != SC_DIR_HIT_READ )  &&
    5302               (r_sc_fsm.read() != SC_DIR_HIT_WRITE ) &&
    5303 //              (r_sc_fsm.read() != SC_MISS_TRT_LOCK )    &&
    5304               (r_sc_fsm.read() != SC_BC_TRT_LOCK)       &&
    5305               (r_sc_fsm.read() != SC_BC_UPT_LOCK)     &&
    5306               (r_sc_fsm.read() != SC_UPT_LOCK)       &&
    5307               (r_sc_fsm.read() != SC_UPT_HEAP_LOCK))
     5754        if ((( r_sc_fsm.read()         != SC_DIR_REQ       )  &&
     5755             ( r_sc_fsm.read()         != SC_DIR_LOCK      )  &&
     5756             ( r_sc_fsm.read()         != SC_DIR_HIT_READ  )  &&
     5757             ( r_sc_fsm.read()         != SC_DIR_HIT_WRITE )  &&
     5758             ( r_sc_fsm.read()         != SC_BC_TRT_LOCK   )  &&
     5759             ( r_sc_fsm.read()         != SC_BC_UPT_LOCK   )  &&
     5760             ( r_sc_fsm.read()         != SC_MISS_TRT_LOCK )  &&
     5761             ( r_sc_fsm.read()         != SC_UPT_LOCK      )  &&
     5762             ( r_sc_fsm.read()         != SC_UPT_HEAP_LOCK ))
    53085763            ||
    5309             ( (r_sc_fsm.read()       == SC_UPT_HEAP_LOCK) &&
    5310               (r_alloc_heap_fsm.read() == ALLOC_HEAP_SC) )
     5764            (( r_sc_fsm.read()         == SC_UPT_HEAP_LOCK ) &&
     5765             ( r_alloc_heap_fsm.read() == ALLOC_HEAP_SC    ))
    53115766            ||
    5312             ( (r_sc_fsm.read()      == SC_MISS_TRT_LOCK ) &&
    5313               (r_alloc_trt_fsm.read() == ALLOC_TRT_SC)    ) )
    5314         {
    5315           if      (r_cleanup_fsm.read() == CLEANUP_DIR_LOCK)    r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
    5316           else if (r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)  r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
    5317           else if (r_read_fsm.read() == READ_DIR_LOCK)          r_alloc_dir_fsm = ALLOC_DIR_READ;
    5318           else if (r_write_fsm.read() == WRITE_DIR_LOCK)        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
     5767            (( r_sc_fsm.read()         == SC_MISS_TRT_LOCK )  &&
     5768             ( r_alloc_trt_fsm.read()  == ALLOC_TRT_SC     )))
     5769        {
     5770          if ( r_cleanup_fsm.read() == CLEANUP_DIR_REQ )
     5771            r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
     5772
     5773          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK )
     5774            r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
     5775
     5776          else if ( r_read_fsm.read() == READ_DIR_REQ )
     5777            r_alloc_dir_fsm = ALLOC_DIR_READ;
     5778
     5779          else if ( r_write_fsm.read() == WRITE_DIR_REQ )
     5780            r_alloc_dir_fsm = ALLOC_DIR_WRITE;
    53195781        }
    53205782        break;
     
    53225784        ///////////////////////
    53235785        case ALLOC_DIR_CLEANUP:
    5324         if ( (r_cleanup_fsm.read() != CLEANUP_DIR_LOCK) &&
    5325             (r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK) )
    5326         {
    5327           if        (r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)    r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
    5328           else if   (r_read_fsm.read() == READ_DIR_LOCK)            r_alloc_dir_fsm = ALLOC_DIR_READ;
    5329           else if   (r_write_fsm.read() == WRITE_DIR_LOCK)          r_alloc_dir_fsm = ALLOC_DIR_WRITE;
    5330           else if   (r_sc_fsm.read() == SC_DIR_LOCK)              r_alloc_dir_fsm = ALLOC_DIR_SC;
     5786        if (( r_cleanup_fsm.read() != CLEANUP_DIR_REQ   ) &&
     5787            ( r_cleanup_fsm.read() != CLEANUP_DIR_LOCK  ) &&
     5788            ( r_cleanup_fsm.read() != CLEANUP_HEAP_REQ  ) &&
     5789            ( r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK ))
     5790        {
     5791          if ( r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK )
     5792            r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
     5793
     5794          else if ( r_read_fsm.read() == READ_DIR_REQ )
     5795            r_alloc_dir_fsm = ALLOC_DIR_READ;
     5796
     5797          else if ( r_write_fsm.read() == WRITE_DIR_REQ )
     5798            r_alloc_dir_fsm = ALLOC_DIR_WRITE;
     5799
     5800          else if ( r_sc_fsm.read() == SC_DIR_REQ )
     5801            r_alloc_dir_fsm = ALLOC_DIR_SC;
    53315802        }
    53325803        break;
     5804
    53335805        ////////////////////////
    53345806        case ALLOC_DIR_XRAM_RSP:
    5335         if ( (r_xram_rsp_fsm.read() != XRAM_RSP_DIR_LOCK)  &&
    5336             (r_xram_rsp_fsm.read() != XRAM_RSP_TRT_COPY)   &&
    5337             (r_xram_rsp_fsm.read() != XRAM_RSP_INVAL_LOCK))
    5338         {
    5339           if      (r_read_fsm.read() == READ_DIR_LOCK)          r_alloc_dir_fsm = ALLOC_DIR_READ;
    5340           else if (r_write_fsm.read() == WRITE_DIR_LOCK)        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
    5341           else if (r_sc_fsm.read() == SC_DIR_LOCK)            r_alloc_dir_fsm = ALLOC_DIR_SC;
    5342           else if (r_cleanup_fsm.read() == CLEANUP_DIR_LOCK)    r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
     5807        if (( r_xram_rsp_fsm.read() != XRAM_RSP_DIR_LOCK   ) &&
     5808            ( r_xram_rsp_fsm.read() != XRAM_RSP_TRT_COPY   ) &&
     5809            ( r_xram_rsp_fsm.read() != XRAM_RSP_INVAL_LOCK ))
     5810        {
     5811          if ( r_read_fsm.read() == READ_DIR_REQ )
     5812            r_alloc_dir_fsm = ALLOC_DIR_READ;
     5813
     5814          else if ( r_write_fsm.read() == WRITE_DIR_REQ )
     5815            r_alloc_dir_fsm = ALLOC_DIR_WRITE;
     5816
     5817          else if ( r_sc_fsm.read() == SC_DIR_REQ )
     5818            r_alloc_dir_fsm = ALLOC_DIR_SC;
     5819
     5820          else if ( r_cleanup_fsm.read() == CLEANUP_DIR_REQ )
     5821            r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
    53435822        }
    53445823        break;
     
    53475826
    53485827    ////////////////////////////////////////////////////////////////////////////////////
    5349     //          ALLOC_TRT FSM
     5828    //    ALLOC_TRT FSM
    53505829    ////////////////////////////////////////////////////////////////////////////////////
    53515830    // The ALLOC_TRT fsm allocates the access to the Transaction Table (write buffer)
     
    53555834    ///////////////////////////////////////////////////////////////////////////////////
    53565835
    5357     switch (r_alloc_trt_fsm)
     5836    switch ( r_alloc_trt_fsm.read() )
    53585837    {
    5359 
    53605838      ////////////////////
    53615839      case ALLOC_TRT_READ:
    5362         if ( r_read_fsm.read() != READ_TRT_LOCK )
    5363         {
    5364           if      ((r_write_fsm.read() == WRITE_MISS_TRT_LOCK)   ||
    5365                    (r_write_fsm.read() == WRITE_BC_TRT_LOCK))    r_alloc_trt_fsm = ALLOC_TRT_WRITE;
    5366           else if ((r_sc_fsm.read() == SC_MISS_TRT_LOCK) ||
    5367                    (r_sc_fsm.read() == SC_BC_TRT_LOCK))              r_alloc_trt_fsm = ALLOC_TRT_SC;
    5368           else if (r_xram_rsp_fsm.read() == XRAM_RSP_TRT_COPY)      r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
    5369           else if ( (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) ||
    5370                     (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ) )    r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
     5840        if ( r_read_fsm.read() != READ_TRT_LOCK )
     5841        {
     5842          if (( r_write_fsm.read() == WRITE_MISS_TRT_LOCK ) ||
     5843              ( r_write_fsm.read() == WRITE_BC_TRT_LOCK   ))
     5844            r_alloc_trt_fsm = ALLOC_TRT_WRITE;
     5845
     5846          else if (( r_sc_fsm.read() == SC_MISS_TRT_LOCK ) ||
     5847                   ( r_sc_fsm.read() == SC_BC_TRT_LOCK   ))
     5848            r_alloc_trt_fsm = ALLOC_TRT_SC;
     5849
     5850          else if (( r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK  ) &&
     5851                   ( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP ))
     5852            r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
     5853
     5854          else if (( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE ) ||
     5855                   ( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ  ))
     5856            r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
    53715857        }
    53725858        break;
    5373         /////////////////////
     5859
     5860      /////////////////////
    53745861      case ALLOC_TRT_WRITE:
    5375         if ( (r_write_fsm.read() != WRITE_MISS_TRT_LOCK) &&
    5376              (r_write_fsm.read() != WRITE_BC_TRT_LOCK) &&
    5377              (r_write_fsm.read() != WRITE_BC_UPT_LOCK))
    5378         {
    5379           if      ((r_sc_fsm.read() == SC_MISS_TRT_LOCK) ||
    5380                    (r_sc_fsm.read() == SC_BC_TRT_LOCK))              r_alloc_trt_fsm = ALLOC_TRT_SC;
    5381           else if (r_xram_rsp_fsm.read() == XRAM_RSP_TRT_COPY)      r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
    5382           else if ( (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) ||
    5383                     (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))     r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
    5384           else if (r_read_fsm.read() == READ_TRT_LOCK)              r_alloc_trt_fsm = ALLOC_TRT_READ;
     5862        if (( r_write_fsm.read() != WRITE_MISS_TRT_LOCK ) &&
     5863            ( r_write_fsm.read() != WRITE_BC_TRT_LOCK   ) &&
     5864            ( r_write_fsm.read() != WRITE_BC_UPT_LOCK   ))
     5865        {
     5866          if (( r_sc_fsm.read() == SC_MISS_TRT_LOCK ) ||
     5867              ( r_sc_fsm.read() == SC_BC_TRT_LOCK   ))
     5868            r_alloc_trt_fsm = ALLOC_TRT_SC;
     5869
     5870          else if (( r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK  ) &&
     5871                   ( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP ))
     5872            r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
     5873
     5874          else if (( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE ) ||
     5875                   ( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ  ))
     5876            r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
     5877
     5878          else if ( r_read_fsm.read() == READ_TRT_LOCK )
     5879            r_alloc_trt_fsm = ALLOC_TRT_READ;
    53855880        }
    53865881        break;
    5387         ////////////////////
     5882
     5883      ////////////////////
    53885884      case ALLOC_TRT_SC:
    5389         if ( (r_sc_fsm.read() != SC_MISS_TRT_LOCK) &&
    5390              (r_sc_fsm.read() != SC_BC_TRT_LOCK) &&
    5391              (r_sc_fsm.read() != SC_BC_UPT_LOCK))
    5392         {
    5393           if      (r_xram_rsp_fsm.read() == XRAM_RSP_TRT_COPY)      r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
    5394           else if ( (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) ||
    5395                     (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))     r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
    5396           else if (r_read_fsm.read() == READ_TRT_LOCK)              r_alloc_trt_fsm = ALLOC_TRT_READ;
    5397           else if ((r_write_fsm.read() == WRITE_MISS_TRT_LOCK)     ||
    5398                    (r_write_fsm.read() == WRITE_BC_TRT_LOCK))    r_alloc_trt_fsm = ALLOC_TRT_WRITE;
     5885        if (( r_sc_fsm.read() != SC_MISS_TRT_LOCK ) &&
     5886            ( r_sc_fsm.read() != SC_BC_TRT_LOCK   ) &&
     5887            ( r_sc_fsm.read() != SC_BC_UPT_LOCK   ))
     5888        {
     5889          if (( r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK  ) &&
     5890              ( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP ))
     5891            r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
     5892
     5893          else if (( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE ) ||
     5894                   ( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ  ))
     5895            r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
     5896
     5897          else if ( r_read_fsm.read() == READ_TRT_LOCK )
     5898            r_alloc_trt_fsm = ALLOC_TRT_READ;
     5899
     5900          else if (( r_write_fsm.read() == WRITE_MISS_TRT_LOCK ) ||
     5901                   ( r_write_fsm.read() == WRITE_BC_TRT_LOCK   ))
     5902            r_alloc_trt_fsm = ALLOC_TRT_WRITE;
    53995903        }
    54005904        break;
    5401         ////////////////////////
     5905
     5906      ////////////////////////
    54025907      case ALLOC_TRT_XRAM_RSP:
    5403         if ( (r_xram_rsp_fsm.read() != XRAM_RSP_TRT_COPY)  &&
    5404             (r_xram_rsp_fsm.read() != XRAM_RSP_DIR_UPDT)   &&
    5405             (r_xram_rsp_fsm.read() != XRAM_RSP_INVAL_LOCK)) {
    5406           if      ( (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) ||
    5407                     (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))     r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
    5408           else if (r_read_fsm.read() == READ_TRT_LOCK)              r_alloc_trt_fsm = ALLOC_TRT_READ;
    5409           else if ((r_write_fsm.read() == WRITE_MISS_TRT_LOCK)    ||
    5410                    (r_write_fsm.read() == WRITE_BC_TRT_LOCK))    r_alloc_trt_fsm = ALLOC_TRT_WRITE;
    5411           else if ((r_sc_fsm.read() == SC_MISS_TRT_LOCK) ||
    5412                    (r_sc_fsm.read() == SC_BC_TRT_LOCK))              r_alloc_trt_fsm = ALLOC_TRT_SC;
     5908        if ((( r_xram_rsp_fsm.read()  != XRAM_RSP_DIR_LOCK   )  ||
     5909             ( r_alloc_dir_fsm.read() != ALLOC_DIR_XRAM_RSP  )) &&
     5910             ( r_xram_rsp_fsm.read()  != XRAM_RSP_TRT_COPY   )  &&
     5911             ( r_xram_rsp_fsm.read()  != XRAM_RSP_DIR_UPDT   )  &&
     5912             ( r_xram_rsp_fsm.read()  != XRAM_RSP_INVAL_LOCK ))
     5913        {
     5914          if (( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE ) ||
     5915              ( r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ  ))
     5916            r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
     5917
     5918          else if ( r_read_fsm.read() == READ_TRT_LOCK )
     5919            r_alloc_trt_fsm = ALLOC_TRT_READ;
     5920
     5921          else if (( r_write_fsm.read() == WRITE_MISS_TRT_LOCK ) ||
     5922                   ( r_write_fsm.read() == WRITE_BC_TRT_LOCK   ))
     5923            r_alloc_trt_fsm = ALLOC_TRT_WRITE;
     5924
     5925          else if (( r_sc_fsm.read() == SC_MISS_TRT_LOCK ) ||
     5926                   ( r_sc_fsm.read() == SC_BC_TRT_LOCK   ))
     5927            r_alloc_trt_fsm = ALLOC_TRT_SC;
    54135928        }
    54145929        break;
    5415         ////////////////////////
     5930
     5931      ////////////////////////
    54165932      case ALLOC_TRT_IXR_RSP:
    5417         if ( (r_ixr_rsp_fsm.read() != IXR_RSP_TRT_ERASE) &&
    5418             (r_ixr_rsp_fsm.read() != IXR_RSP_TRT_READ) ) {
    5419           if      (r_read_fsm.read() == READ_TRT_LOCK)              r_alloc_trt_fsm = ALLOC_TRT_READ;
    5420           else if ((r_write_fsm.read() == WRITE_MISS_TRT_LOCK)   ||
    5421                    (r_write_fsm.read() == WRITE_BC_TRT_LOCK))    r_alloc_trt_fsm = ALLOC_TRT_WRITE;
    5422           else if ((r_sc_fsm.read() == SC_MISS_TRT_LOCK) ||
    5423                    (r_sc_fsm.read() == SC_BC_TRT_LOCK))              r_alloc_trt_fsm = ALLOC_TRT_SC;
    5424           else if (r_xram_rsp_fsm.read() == XRAM_RSP_TRT_COPY)      r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
     5933        if (( r_ixr_rsp_fsm.read() != IXR_RSP_TRT_ERASE ) &&
     5934            ( r_ixr_rsp_fsm.read() != IXR_RSP_TRT_READ  ))
     5935        {
     5936          if ( r_read_fsm.read() == READ_TRT_LOCK )
     5937            r_alloc_trt_fsm = ALLOC_TRT_READ;
     5938
     5939          else if (( r_write_fsm.read() == WRITE_MISS_TRT_LOCK ) ||
     5940                   ( r_write_fsm.read() == WRITE_BC_TRT_LOCK   ))
     5941            r_alloc_trt_fsm = ALLOC_TRT_WRITE;
     5942
     5943          else if (( r_sc_fsm.read() == SC_MISS_TRT_LOCK ) ||
     5944                   ( r_sc_fsm.read() == SC_BC_TRT_LOCK   ))
     5945            r_alloc_trt_fsm = ALLOC_TRT_SC;
     5946
     5947          else if (( r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK  ) &&
     5948                   ( r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP ))
     5949            r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
    54255950        }
    54265951        break;
     
    54295954
    54305955    ////////////////////////////////////////////////////////////////////////////////////
    5431     //          ALLOC_HEAP FSM
     5956    //    ALLOC_HEAP FSM
    54325957    ////////////////////////////////////////////////////////////////////////////////////
    54335958    // The ALLOC_HEAP FSM allocates the access to the heap
     
    54375962    /////////////////////////////////////////////////////////////////////////////////////
    54385963
    5439     switch ( r_alloc_heap_fsm.read() ) 
     5964    switch ( r_alloc_heap_fsm.read() )
    54405965    {
    54415966        ////////////////////
     5967        case ALLOC_HEAP_RESET:
     5968          // Initializes the heap one ENTRY each cycle.
     5969
     5970          r_alloc_heap_reset_cpt.write(r_alloc_heap_reset_cpt.read() + 1);
     5971
     5972          if(r_alloc_heap_reset_cpt.read() == (m_heap_size-1)) {
     5973            m_heap.init();
     5974
     5975            r_alloc_heap_fsm = ALLOC_HEAP_READ;
     5976          }
     5977          break;
     5978
     5979        ////////////////////
    54425980        case ALLOC_HEAP_READ:
    5443         if (  (r_read_fsm.read() != READ_HEAP_LOCK) &&
    5444               (r_read_fsm.read() != READ_HEAP_ERASE)     )
    5445         {
    5446           if      (r_write_fsm.read() == WRITE_UPT_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
    5447           else if (r_sc_fsm.read() == SC_UPT_HEAP_LOCK)              r_alloc_heap_fsm = ALLOC_HEAP_SC;
    5448           else if (r_cleanup_fsm.read() == CLEANUP_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
    5449           else if (r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_ERASE) r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
     5981        if (( r_read_fsm.read() != READ_HEAP_REQ   ) &&
     5982            ( r_read_fsm.read() != READ_HEAP_LOCK  ) &&
     5983            ( r_read_fsm.read() != READ_HEAP_ERASE ))
     5984        {
     5985          if ( r_write_fsm.read() == WRITE_UPT_HEAP_LOCK )
     5986            r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
     5987
     5988          else if ( r_sc_fsm.read() == SC_UPT_HEAP_LOCK )
     5989            r_alloc_heap_fsm = ALLOC_HEAP_SC;
     5990
     5991          else if ( r_cleanup_fsm.read() == CLEANUP_HEAP_REQ )
     5992            r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
     5993
     5994          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ )
     5995            r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
    54505996        }
    54515997        break;
     
    54535999        /////////////////////
    54546000        case ALLOC_HEAP_WRITE:
    5455         if (  (r_write_fsm.read() != WRITE_UPT_HEAP_LOCK)   &&
    5456               (r_write_fsm.read() != WRITE_UPT_REQ)     &&
    5457               (r_write_fsm.read() != WRITE_UPT_NEXT)  )
    5458         {
    5459           if      (r_sc_fsm.read() == SC_UPT_HEAP_LOCK)          r_alloc_heap_fsm = ALLOC_HEAP_SC;
    5460           else if (r_cleanup_fsm.read() == CLEANUP_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
    5461           else if (r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_ERASE) r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
    5462           else if (r_read_fsm.read() == READ_HEAP_LOCK)              r_alloc_heap_fsm = ALLOC_HEAP_READ;
     6001        if (( r_write_fsm.read() != WRITE_UPT_HEAP_LOCK ) &&
     6002            ( r_write_fsm.read() != WRITE_UPT_REQ       ) &&
     6003            ( r_write_fsm.read() != WRITE_UPT_NEXT      ))
     6004        {
     6005          if ( r_sc_fsm.read() == SC_UPT_HEAP_LOCK )
     6006            r_alloc_heap_fsm = ALLOC_HEAP_SC;
     6007
     6008          else if ( r_cleanup_fsm.read() == CLEANUP_HEAP_REQ )
     6009            r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
     6010
     6011          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ )
     6012            r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
     6013
     6014          else if ( r_read_fsm.read() == READ_HEAP_REQ )
     6015            r_alloc_heap_fsm = ALLOC_HEAP_READ;
    54636016        }
    54646017        break;
     
    54666019        ////////////////////
    54676020        case ALLOC_HEAP_SC:
    5468         if (  (r_sc_fsm.read() != SC_UPT_HEAP_LOCK)  &&
    5469               (r_sc_fsm.read() != SC_UPT_REQ )    &&
    5470               (r_sc_fsm.read() != SC_UPT_NEXT)  )
    5471         {
    5472           if      (r_cleanup_fsm.read() == CLEANUP_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
    5473           else if (r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_ERASE) r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
    5474           else if (r_read_fsm.read() == READ_HEAP_LOCK)          r_alloc_heap_fsm = ALLOC_HEAP_READ;
    5475           else if (r_write_fsm.read() == WRITE_UPT_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
     6021        if (( r_sc_fsm.read() != SC_UPT_HEAP_LOCK ) &&
     6022            ( r_sc_fsm.read() != SC_UPT_REQ       ) &&
     6023            ( r_sc_fsm.read() != SC_UPT_NEXT      ))
     6024        {
     6025          if ( r_cleanup_fsm.read() == CLEANUP_HEAP_REQ )
     6026            r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
     6027
     6028          else if ( r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ )
     6029            r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
     6030
     6031          else if ( r_read_fsm.read() == READ_HEAP_REQ )
     6032            r_alloc_heap_fsm = ALLOC_HEAP_READ;
     6033
     6034          else if ( r_write_fsm.read() == WRITE_UPT_HEAP_LOCK )
     6035            r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
    54766036        }
    54776037        break;
     
    54796039        ///////////////////////
    54806040        case ALLOC_HEAP_CLEANUP:
    5481         if ( (r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK) &&
    5482             (r_cleanup_fsm.read() != CLEANUP_HEAP_SEARCH)&&
    5483             (r_cleanup_fsm.read() != CLEANUP_HEAP_CLEAN)    )
    5484         {
    5485           if      (r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_ERASE) r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
    5486           else if (r_read_fsm.read() == READ_HEAP_LOCK)          r_alloc_heap_fsm = ALLOC_HEAP_READ;
    5487           else if (r_write_fsm.read() == WRITE_UPT_HEAP_LOCK)    r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
    5488           else if (r_sc_fsm.read() == SC_UPT_HEAP_LOCK)          r_alloc_heap_fsm = ALLOC_HEAP_SC;
     6041        if (( r_cleanup_fsm.read() != CLEANUP_HEAP_REQ    ) &&
     6042            ( r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK   ) &&
     6043            ( r_cleanup_fsm.read() != CLEANUP_HEAP_SEARCH ) &&
     6044            ( r_cleanup_fsm.read() != CLEANUP_HEAP_CLEAN  ))
     6045        {
     6046          if ( r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ )
     6047            r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
     6048
     6049          else if ( r_read_fsm.read() == READ_HEAP_REQ )
     6050            r_alloc_heap_fsm = ALLOC_HEAP_READ;
     6051
     6052          else if ( r_write_fsm.read() == WRITE_UPT_HEAP_LOCK )
     6053            r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
     6054
     6055          else if ( r_sc_fsm.read() == SC_UPT_HEAP_LOCK )
     6056            r_alloc_heap_fsm = ALLOC_HEAP_SC;
    54896057        }
    54906058        break;
     6059
    54916060        ////////////////////////
    54926061        case ALLOC_HEAP_XRAM_RSP:
    5493         if ( r_xram_rsp_fsm.read() != XRAM_RSP_HEAP_ERASE )
    5494         {
    5495           if        (r_read_fsm.read() == READ_HEAP_LOCK)           r_alloc_heap_fsm = ALLOC_HEAP_READ;
    5496           else if   (r_write_fsm.read() == WRITE_UPT_HEAP_LOCK) r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
    5497           else if   (r_sc_fsm.read() == SC_UPT_HEAP_LOCK)       r_alloc_heap_fsm = ALLOC_HEAP_SC;
    5498           else if   (r_cleanup_fsm.read() == CLEANUP_HEAP_LOCK) r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
     6062        if (( r_xram_rsp_fsm.read() != XRAM_RSP_HEAP_REQ   ) &&
     6063            ( r_xram_rsp_fsm.read() != XRAM_RSP_HEAP_ERASE ))
     6064        {
     6065          if  ( r_read_fsm.read() == READ_HEAP_REQ )
     6066            r_alloc_heap_fsm = ALLOC_HEAP_READ;
     6067
     6068          else if ( r_write_fsm.read() == WRITE_UPT_HEAP_LOCK )
     6069            r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
     6070
     6071          else if ( r_sc_fsm.read() == SC_UPT_HEAP_LOCK )
     6072            r_alloc_heap_fsm = ALLOC_HEAP_SC;
     6073
     6074          else if ( r_cleanup_fsm.read() == CLEANUP_HEAP_REQ )
     6075            r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
     6076
    54996077        }
    55006078        break;
     
    55046082
    55056083    ////////////////////////////////////////////////////////////////////////////////////
    5506     //          TGT_CMD to READ FIFO
     6084    //    TGT_CMD to READ FIFO
    55076085    ////////////////////////////////////////////////////////////////////////////////////
    55086086
     
    55316109    }
    55326110    /////////////////////////////////////////////////////////////////////
    5533     //          TGT_CMD to WRITE FIFO
     6111    //    TGT_CMD to WRITE FIFO
    55346112    /////////////////////////////////////////////////////////////////////
    55356113
     
    55646142    }
    55656143    ////////////////////////////////////////////////////////////////////////////////////
    5566     //          TGT_CMD to SC FIFO
     6144    //    TGT_CMD to SC FIFO
    55676145    ////////////////////////////////////////////////////////////////////////////////////
    55686146
     
    55706148      if ( cmd_sc_fifo_get ) {
    55716149        m_cmd_sc_addr_fifo.put_and_get((addr_t)(p_vci_tgt.address.read()));
    5572         m_cmd_sc_eop_fifo.put_and_get(p_vci_tgt.eop.read()); 
     6150        m_cmd_sc_eop_fifo.put_and_get(p_vci_tgt.eop.read());
    55736151        m_cmd_sc_srcid_fifo.put_and_get(p_vci_tgt.srcid.read());
    55746152        m_cmd_sc_trdid_fifo.put_and_get(p_vci_tgt.trdid.read());
     
    55776155      } else {
    55786156        m_cmd_sc_addr_fifo.simple_put((addr_t)(p_vci_tgt.address.read()));
    5579         m_cmd_sc_eop_fifo.simple_put(p_vci_tgt.eop.read()); 
     6157        m_cmd_sc_eop_fifo.simple_put(p_vci_tgt.eop.read());
    55806158        m_cmd_sc_srcid_fifo.simple_put(p_vci_tgt.srcid.read());
    55816159        m_cmd_sc_trdid_fifo.simple_put(p_vci_tgt.trdid.read());
     
    55946172    }
    55956173    ////////////////////////////////////////////////////////////////////////////////////
    5596     //          WRITE to INIT_CMD FIFO
     6174    //    WRITE to INIT_CMD FIFO
    55976175    ////////////////////////////////////////////////////////////////////////////////////
    55986176
     
    56216199    }
    56226200    ////////////////////////////////////////////////////////////////////////////////////
    5623     //          XRAM_RSP to INIT_CMD FIFO
     6201    //    XRAM_RSP to INIT_CMD FIFO
    56246202    ////////////////////////////////////////////////////////////////////////////////////
    56256203
     
    56486226    }
    56496227    ////////////////////////////////////////////////////////////////////////////////////
    5650     //          SC to INIT_CMD FIFO
     6228    //    SC to INIT_CMD FIFO
    56516229    ////////////////////////////////////////////////////////////////////////////////////
    56526230
     
    57046282      p_vci_ixr.trdid   = r_read_to_ixr_cmd_trdid.read();
    57056283      p_vci_ixr.eop     = true;
    5706     } 
     6284    }
    57076285    else if ( r_ixr_cmd_fsm.read() == IXR_CMD_SC_NLINE ) {
    57086286      if(r_sc_to_ixr_cmd_write.read()){
     
    57236301        p_vci_ixr.eop     = true;
    57246302      }
    5725     } 
     6303    }
    57266304    else if ( r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_NLINE ) {
    57276305      if(r_write_to_ixr_cmd_write.read()){
     
    57426320        p_vci_ixr.eop     = true;
    57436321      }
    5744     } 
     6322    }
    57456323    else if ( r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_DATA ) {
    57466324      p_vci_ixr.cmd     = vci_param::CMD_WRITE;
     
    57576335      p_vci_ixr.wdata   = 0;
    57586336      p_vci_ixr.trdid   = 0;
    5759       p_vci_ixr.eop     = false;
     6337      p_vci_ixr.eop = false;
    57606338    }
    57616339
     
    57656343
    57666344    if ( ((r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP) &&
    5767           (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ)) || 
     6345          (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ)) ||
    57686346        (r_ixr_rsp_fsm.read() == IXR_RSP_ACK) ) p_vci_ixr.rspack = true;
    57696347    else                                        p_vci_ixr.rspack = false;
     
    58086386        p_vci_tgt.rtrdid  = 0;
    58096387        p_vci_tgt.rerror  = 0;
    5810         p_vci_tgt.reop    = false;     
     6388        p_vci_tgt.reop    = false;
    58116389        break;
    58126390      case TGT_RSP_READ:
     
    58256403        p_vci_tgt.rtrdid   = r_write_to_tgt_rsp_trdid.read();
    58266404        p_vci_tgt.rpktid   = r_write_to_tgt_rsp_pktid.read();
    5827         p_vci_tgt.rerror   = 0x2 & ( (1 << vci_param::E) - 1); 
     6405        p_vci_tgt.rerror   = 0x2 & ( (1 << vci_param::E) - 1);
    58286406        p_vci_tgt.reop     = true;
    58296407        break;
     
    58536431        p_vci_tgt.rpktid   = r_xram_rsp_to_tgt_rsp_pktid.read();
    58546432        p_vci_tgt.rerror   = r_xram_rsp_to_tgt_rsp_rerror.read();
    5855         p_vci_tgt.reop     = (( r_tgt_rsp_cpt.read() 
    5856                                 == (r_xram_rsp_to_tgt_rsp_word.read()+r_xram_rsp_to_tgt_rsp_length.read()-1))
    5857                               || r_xram_rsp_to_tgt_rsp_rerror.read());
     6433        p_vci_tgt.reop     = (( r_tgt_rsp_cpt.read()
     6434              == (r_xram_rsp_to_tgt_rsp_word.read()+r_xram_rsp_to_tgt_rsp_length.read()-1))
     6435            || r_xram_rsp_to_tgt_rsp_rerror.read());
    58586436        break;
    58596437      case TGT_RSP_INIT:
     
    58646442        p_vci_tgt.rpktid   = r_init_rsp_to_tgt_rsp_pktid.read();
    58656443        p_vci_tgt.rerror   = 0; // Can be a SC rsp
    5866         p_vci_tgt.reop     = true;     
     6444        p_vci_tgt.reop     = true;
    58676445        break;
    58686446    } // end switch r_tgt_rsp_fsm
     
    61436721// End:
    61446722
    6145 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    6146 
     6723// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=2:softtabstop=2
Note: See TracChangeset for help on using the changeset viewer.