Ignore:
Timestamp:
Sep 3, 2014, 2:38:01 PM (10 years ago)
Author:
meunier
Message:

Trunk:

  • Improving counters precision in vci_mem_cache, especially for cost (flits * hops) computation
  • Cosmetic in vci_cc_vcache
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/vci_cc_vcache_wrapper/caba/source/src/vci_cc_vcache_wrapper.cpp

    r752 r789  
    3434#include "../include/vci_cc_vcache_wrapper.h"
    3535
    36 #define DEBUG_DCACHE            1
    37 #define DEBUG_ICACHE            1
    38 #define DEBUG_CMD               0
     36#define DEBUG_DCACHE    1
     37#define DEBUG_ICACHE    1
     38#define DEBUG_CMD       0
    3939
    4040namespace soclib {
     
    4242
    4343namespace {
    44 const char *icache_fsm_state_str[] = {
     44const char * icache_fsm_state_str[] = {
    4545        "ICACHE_IDLE",
    4646
     
    6868    };
    6969
    70 const char *dcache_fsm_state_str[] = {
     70const char * dcache_fsm_state_str[] = {
    7171        "DCACHE_IDLE",
    7272
     
    117117    };
    118118
    119 const char *cmd_fsm_state_str[] = {
     119const char * cmd_fsm_state_str[] = {
    120120        "CMD_IDLE",
    121121        "CMD_INS_MISS",
     
    130130    };
    131131
    132 const char *vci_pktid_type_str[] = {
     132const char * vci_pktid_type_str[] = {
    133133        "TYPE_DATA_UNC",
    134134        "TYPE_READ_DATA_MISS",           
     
    141141    };
    142142
    143 const char *vci_cmd_type_str[] = {
     143const char * vci_cmd_type_str[] = {
    144144        "NOP or STORE_COND",
    145145        "READ",
     
    148148    };
    149149
    150 const char *rsp_fsm_state_str[] = {
     150const char * rsp_fsm_state_str[] = {
    151151        "RSP_IDLE",
    152152        "RSP_INS_MISS",
     
    158158    };
    159159
    160 const char *cc_receive_fsm_state_str[] = {
     160const char * cc_receive_fsm_state_str[] = {
    161161        "CC_RECEIVE_IDLE",
    162162        "CC_RECEIVE_BRDCAST_HEADER",
     
    174174    };
    175175
    176 const char *cc_send_fsm_state_str[] = {
     176const char * cc_send_fsm_state_str[] = {
    177177        "CC_SEND_IDLE",
    178178        "CC_SEND_CLEANUP_1",
     
    193193/////////////////////////////////
    194194tmpl(/**/)::VciCcVCacheWrapper(
    195     sc_module_name                      name,
    196     const int                           proc_id,
    197     const MappingTable      &mtd,
    198     const IntTab                &srcid,
    199     const size_t                cc_global_id,
    200     const size_t                        itlb_ways,
    201     const size_t                        itlb_sets,
    202     const size_t                        dtlb_ways,
    203     const size_t                        dtlb_sets,
    204     const size_t                        icache_ways,
    205     const size_t                        icache_sets,
    206     const size_t                        icache_words,
    207     const size_t                        dcache_ways,
    208     const size_t                        dcache_sets,
    209     const size_t                        dcache_words,
    210     const size_t                        wbuf_nlines,
    211     const size_t                        wbuf_nwords,
    212     const size_t                        x_width,
    213     const size_t                        y_width,
    214     const uint32_t                      max_frozen_cycles,
    215     const uint32_t                      debug_start_cycle,
    216     const bool                          debug_ok )
     195    sc_module_name name,
     196    const int proc_id,
     197    const MappingTable &mtd,
     198    const IntTab &srcid,
     199    const size_t cc_global_id,
     200    const size_t itlb_ways,
     201    const size_t itlb_sets,
     202    const size_t dtlb_ways,
     203    const size_t dtlb_sets,
     204    const size_t icache_ways,
     205    const size_t icache_sets,
     206    const size_t icache_words,
     207    const size_t dcache_ways,
     208    const size_t dcache_sets,
     209    const size_t dcache_words,
     210    const size_t wbuf_nlines,
     211    const size_t wbuf_nwords,
     212    const size_t x_width,
     213    const size_t y_width,
     214    const uint32_t max_frozen_cycles,
     215    const uint32_t debug_start_cycle,
     216    const bool debug_ok)
    217217    : soclib::caba::BaseModule(name),
    218218
     
    224224      p_dspin_clack("p_dspin_clack"),
    225225
    226       m_cacheability_table( mtd.getCacheabilityTable() ),
    227       m_srcid( mtd.indexForId(srcid) ),
    228       m_cc_global_id( cc_global_id ),
    229       m_nline_width( vci_param::N - (uint32_log2(dcache_words)) - 2 ),
    230       m_itlb_ways( itlb_ways ),
    231       m_itlb_sets( itlb_sets ),
    232       m_dtlb_ways( dtlb_ways ),
    233       m_dtlb_sets( dtlb_sets ),
    234       m_icache_ways( icache_ways ),
    235       m_icache_sets( icache_sets ),
    236       m_icache_yzmask( (~0)<<(uint32_log2(icache_words) + 2) ),
    237       m_icache_words( icache_words ),
    238       m_dcache_ways( dcache_ways ),
    239       m_dcache_sets( dcache_sets ),
    240       m_dcache_yzmask( (~0)<<(uint32_log2(dcache_words) + 2) ),
    241       m_dcache_words( dcache_words ),
    242       m_x_width( x_width ),
    243       m_y_width( y_width ),
    244       m_proc_id( proc_id ),
    245       m_max_frozen_cycles( max_frozen_cycles ),
    246       m_paddr_nbits( vci_param::N ),
    247       m_debug_start_cycle( debug_start_cycle ),
    248       m_debug_ok( debug_ok ),
     226      m_cacheability_table( mtd.getCacheabilityTable()),
     227      m_srcid(mtd.indexForId(srcid)),
     228      m_cc_global_id(cc_global_id),
     229      m_nline_width(vci_param::N - (uint32_log2(dcache_words)) - 2),
     230      m_itlb_ways(itlb_ways),
     231      m_itlb_sets(itlb_sets),
     232      m_dtlb_ways(dtlb_ways),
     233      m_dtlb_sets(dtlb_sets),
     234      m_icache_ways(icache_ways),
     235      m_icache_sets(icache_sets),
     236      m_icache_yzmask((~0) << (uint32_log2(icache_words) + 2)),
     237      m_icache_words(icache_words),
     238      m_dcache_ways(dcache_ways),
     239      m_dcache_sets(dcache_sets),
     240      m_dcache_yzmask((~0) << (uint32_log2(dcache_words) + 2)),
     241      m_dcache_words(dcache_words),
     242      m_x_width(x_width),
     243      m_y_width(y_width),
     244      m_proc_id(proc_id),
     245      m_max_frozen_cycles(max_frozen_cycles),
     246      m_paddr_nbits(vci_param::N),
     247      m_debug_start_cycle(debug_start_cycle),
     248      m_debug_ok(debug_ok),
    249249      m_dcache_paddr_ext_reset(0),
    250250      m_icache_paddr_ext_reset(0),
     
    376376      r_vci_rsp_ins_error("r_vci_rsp_ins_error"),
    377377      r_vci_rsp_data_error("r_vci_rsp_data_error"),
    378       r_vci_rsp_fifo_icache("r_vci_rsp_fifo_icache", 2),        // 2 words depth
    379       r_vci_rsp_fifo_dcache("r_vci_rsp_fifo_dcache", 2),        // 2 words depth
     378      r_vci_rsp_fifo_icache("r_vci_rsp_fifo_icache", 2), // 2 words depth
     379      r_vci_rsp_fifo_dcache("r_vci_rsp_fifo_dcache", 2), // 2 words depth
    380380
    381381      r_cc_send_fsm("r_cc_send_fsm"),
     
    385385      r_cc_receive_data_ins("r_cc_receive_data_ins"),
    386386      r_cc_receive_word_idx("r_cc_receive_word_idx"),
    387       r_cc_receive_updt_fifo_be("r_cc_receive_updt_fifo_be", 2),        // 2 words depth
    388       r_cc_receive_updt_fifo_data("r_cc_receive_updt_fifo_data", 2),    // 2 words depth
    389       r_cc_receive_updt_fifo_eop("r_cc_receive_updt_fifo_eop", 2),      // 2 words depth
     387      r_cc_receive_updt_fifo_be("r_cc_receive_updt_fifo_be", 2), // 2 words depth
     388      r_cc_receive_updt_fifo_data("r_cc_receive_updt_fifo_data", 2), // 2 words depth
     389      r_cc_receive_updt_fifo_eop("r_cc_receive_updt_fifo_eop", 2), // 2 words depth
    390390
    391391      r_cc_receive_icache_req("r_cc_receive_icache_req"),
     
    412412    std::cout << "  - Building VciCcVcacheWrapper : " << name << std::endl;
    413413
    414     assert( ((icache_words*vci_param::B) < (1<<vci_param::K)) and
     414    assert(((icache_words*vci_param::B) < (1 << vci_param::K)) and
    415415             "Need more PLEN bits.");
    416416
    417     assert( (vci_param::T > 2) and ((1<<(vci_param::T-1)) >= (wbuf_nlines)) and
     417    assert((vci_param::T > 2) and ((1 << (vci_param::T - 1)) >= (wbuf_nlines)) and
    418418             "Need more TRDID bits.");
    419419
    420     assert( (icache_words == dcache_words) and
     420    assert((icache_words == dcache_words) and
    421421             "icache_words and dcache_words parameters must be equal");
    422422
    423     assert( (itlb_sets == dtlb_sets) and
     423    assert((itlb_sets == dtlb_sets) and
    424424             "itlb_sets and dtlb_sets parameters must be etqual");
    425425
    426     assert( (itlb_ways == dtlb_ways) and
     426    assert((itlb_ways == dtlb_ways) and
    427427             "itlb_ways and dtlb_ways parameters must be etqual");
    428428
    429     r_mmu_params = (uint32_log2(m_dtlb_ways)   << 29)   | (uint32_log2(m_dtlb_sets)   << 25) |
    430                    (uint32_log2(m_dcache_ways) << 22)   | (uint32_log2(m_dcache_sets) << 18) |
    431                    (uint32_log2(m_itlb_ways)   << 15)   | (uint32_log2(m_itlb_sets)   << 11) |
    432                    (uint32_log2(m_icache_ways) << 8)    | (uint32_log2(m_icache_sets) << 4)  |
    433                    (uint32_log2(m_icache_words<<2));
    434 
    435     r_mmu_release = (uint32_t)(1 << 16) | 0x1;
    436 
    437     r_dcache_in_tlb       = new bool[dcache_ways*dcache_sets];
    438     r_dcache_contains_ptd = new bool[dcache_ways*dcache_sets];
     429    r_mmu_params = (uint32_log2(m_dtlb_ways)   << 29) | (uint32_log2(m_dtlb_sets)   << 25) |
     430                   (uint32_log2(m_dcache_ways) << 22) | (uint32_log2(m_dcache_sets) << 18) |
     431                   (uint32_log2(m_itlb_ways)   << 15) | (uint32_log2(m_itlb_sets)   << 11) |
     432                   (uint32_log2(m_icache_ways) << 8)  | (uint32_log2(m_icache_sets) << 4)  |
     433                   (uint32_log2(m_icache_words << 2));
     434
     435    r_mmu_release = (uint32_t) (1 << 16) | 0x1;
     436
     437    r_dcache_in_tlb       = new bool[dcache_ways * dcache_sets];
     438    r_dcache_contains_ptd = new bool[dcache_ways * dcache_sets];
    439439
    440440    SC_METHOD(transition);
     
    448448    typename iss_t::CacheInfo cache_info;
    449449    cache_info.has_mmu = true;
    450     cache_info.icache_line_size = icache_words*sizeof(uint32_t);
     450    cache_info.icache_line_size = icache_words * sizeof(uint32_t);
    451451    cache_info.icache_assoc = icache_ways;
    452452    cache_info.icache_n_lines = icache_sets;
    453     cache_info.dcache_line_size = dcache_words*sizeof(uint32_t);
     453    cache_info.dcache_line_size = dcache_words * sizeof(uint32_t);
    454454    cache_info.dcache_assoc = dcache_ways;
    455455    cache_info.dcache_n_lines = dcache_sets;
     
    500500              << " | MMU = " << r_mmu_mode.read();
    501501
    502     if (r_dcache_updt_req.read() ) std::cout << " | P1_UPDT";
    503     if (r_dcache_wbuf_req.read() ) std::cout << " | P1_WBUF";
     502    if (r_dcache_updt_req.read()) std::cout << " | P1_UPDT";
     503    if (r_dcache_wbuf_req.read()) std::cout << " | P1_WBUF";
    504504    std::cout << std::endl;
    505505
    506     if(mode & 0x01)
    507     {
    508         if ( r_icache_miss_req.read()     ) std::cout << "  IMISS_REQ" << std::endl;
    509         if ( r_icache_unc_req.read()      ) std::cout << "  IUNC_REQ" << std::endl;
    510         if ( r_dcache_vci_miss_req.read() ) std::cout << "  DMISS_REQ" << std::endl;
    511         if ( r_dcache_vci_unc_req.read()  ) std::cout << "  DUNC_REQ" << std::endl;
    512 
    513         r_wbuf.printTrace((mode>>1)&1);
    514     }
    515     if(mode & 0x02)
     506    if (mode & 0x01)
     507    {
     508        if (r_icache_miss_req.read())    std::cout << "  IMISS_REQ" << std::endl;
     509        if (r_icache_unc_req.read())      std::cout << "  IUNC_REQ" << std::endl;
     510        if (r_dcache_vci_miss_req.read()) std::cout << "  DMISS_REQ" << std::endl;
     511        if (r_dcache_vci_unc_req.read()) std::cout << "  DUNC_REQ" << std::endl;
     512
     513        r_wbuf.printTrace((mode >> 1) & 1);
     514    }
     515    if (mode & 0x02)
    516516    {
    517517        r_iss.dump();
    518518    }
    519     if(mode & 0x04)
     519    if (mode & 0x04)
    520520    {
    521521        std::cout << "  Data Cache" << std::endl;
    522522        r_dcache.printTrace();
    523523    }
    524     if(mode & 0x08)
     524    if (mode & 0x08)
    525525    {
    526526        std::cout << "  Instruction Cache" << std::endl;
    527527        r_icache.printTrace();
    528528    }
    529     if(mode & 0x10)
     529    if (mode & 0x10)
    530530    {
    531531        std::cout << "  Data TLB" << std::endl;
    532532        r_dtlb.printTrace();
    533533    }
    534     if(mode & 0x20)
     534    if (mode & 0x20)
    535535    {
    536536        std::cout << "  Instruction TLB" << std::endl;
    537537        r_itlb.printTrace();
    538538    }
    539     if(mode & 0x40)
    540     {
    541         uint32_t status = r_iss.debugGetRegisterValue( 32 );
     539    if (mode & 0x40)
     540    {
     541        uint32_t status = r_iss.debugGetRegisterValue(32);
    542542        std::cout << name();
    543         if ( status != m_previous_status ) std::cout << " NEW ";
     543        if (status != m_previous_status ) std::cout << " NEW ";
    544544        std::cout << " status = " << std::hex << status << " " << std::endl;
    545545        m_previous_status = status;
     
    548548
    549549//////////////////////////////////////////
    550 tmpl(void)::cache_monitor( paddr_t addr )
     550tmpl(void)::cache_monitor(paddr_t addr)
    551551//////////////////////////////////////////
    552552{
    553     bool        cache_hit;
    554     size_t          cache_way = 0;
    555     size_t          cache_set = 0;
    556     size_t          cache_word = 0;
    557     uint32_t    cache_rdata = 0;
    558 
    559     cache_hit = r_dcache.read_neutral( addr,
    560                                        &cache_rdata,
    561                                        &cache_way,
    562                                        &cache_set,
    563                                        &cache_word );
    564 
    565     if ( cache_hit != m_debug_previous_d_hit )
     553    bool cache_hit;
     554    size_t cache_way = 0;
     555    size_t cache_set = 0;
     556    size_t cache_word = 0;
     557    uint32_t cache_rdata = 0;
     558
     559    cache_hit = r_dcache.read_neutral(addr,
     560                                      &cache_rdata,
     561                                      &cache_way,
     562                                      &cache_set,
     563                                      &cache_word);
     564
     565    if (cache_hit != m_debug_previous_d_hit)
    566566    {
    567567        std::cout << "Monitor PROC " << name()
     
    571571                  << " / DATA = " << cache_rdata
    572572                  << " / WAY = " << cache_way << std::endl;
    573             m_debug_previous_d_hit = cache_hit;
    574     }
    575 
    576     cache_hit = r_icache.read_neutral( addr,
    577                                        &cache_rdata,
    578                                        &cache_way,
    579                                        &cache_set,
    580                                        &cache_word );
    581 
    582     if ( cache_hit != m_debug_previous_i_hit )
     573        m_debug_previous_d_hit = cache_hit;
     574    }
     575
     576    cache_hit = r_icache.read_neutral(addr,
     577                                      &cache_rdata,
     578                                      &cache_way,
     579                                      &cache_set,
     580                                      &cache_word);
     581
     582    if (cache_hit != m_debug_previous_i_hit)
    583583    {
    584584        std::cout << "Monitor PROC " << name()
     
    588588                  << " / DATA = " << cache_rdata
    589589                  << " / WAY = " << cache_way << std::endl;
    590             m_debug_previous_i_hit = cache_hit;
     590        m_debug_previous_i_hit = cache_hit;
    591591    }
    592592}
     
    742742/////////////////////////
    743743{
    744     if ( not p_resetn.read() )
     744    if (not p_resetn.read())
    745745    {
    746746        r_iss.reset();
     
    751751        r_dtlb.reset();
    752752
    753         r_dcache_fsm      = DCACHE_IDLE;
    754         r_icache_fsm      = ICACHE_IDLE;
    755         r_vci_cmd_fsm     = CMD_IDLE;
    756         r_vci_rsp_fsm     = RSP_IDLE;
    757         r_cc_receive_fsm  = CC_RECEIVE_IDLE;
    758         r_cc_send_fsm     = CC_SEND_IDLE;
     753        r_dcache_fsm     = DCACHE_IDLE;
     754        r_icache_fsm     = ICACHE_IDLE;
     755        r_vci_cmd_fsm    = CMD_IDLE;
     756        r_vci_rsp_fsm    = RSP_IDLE;
     757        r_cc_receive_fsm = CC_RECEIVE_IDLE;
     758        r_cc_send_fsm    = CC_SEND_IDLE;
    759759
    760760        // reset data physical address extension
     
    765765
    766766        // reset dcache directory extension
    767         for (size_t i=0 ; i< m_dcache_ways*m_dcache_sets ; i++)
    768         {
    769             r_dcache_in_tlb[i]       = false;
     767        for (size_t i = 0; i< m_dcache_ways * m_dcache_sets; i++)
     768        {
     769            r_dcache_in_tlb[i] = false;
    770770            r_dcache_contains_ptd[i] = false;
    771771        }
     
    779779        r_mmu_mode = 0x3;
    780780
    781             // No request from ICACHE FSM to CMD FSM
     781        // No request from ICACHE FSM to CMD FSM
    782782        r_icache_miss_req          = false;
    783783        r_icache_unc_req           = false;
     
    807807
    808808        // No request from DCACHE FSM to CC_SEND FSM
    809         r_dcache_cc_send_req       = false;
     809        r_dcache_cc_send_req        = false;
    810810        r_dcache_cleanup_victim_req = false;
    811811
     
    836836        m_debug_previous_i_hit     = false;
    837837        m_debug_previous_d_hit     = false;
    838         m_debug_icache_fsm             = false;
    839         m_debug_dcache_fsm             = false;
    840         m_debug_cmd_fsm                = false;
     838        m_debug_icache_fsm         = false;
     839        m_debug_dcache_fsm         = false;
     840        m_debug_cmd_fsm            = false;
    841841
    842842        // activity counters
     
    899899        m_cost_data_tlb_occup_cache_frz  = 0;
    900900
    901         m_cpt_ins_tlb_inval       = 0;
    902         m_cpt_data_tlb_inval      = 0;
    903         m_cost_ins_tlb_inval_frz  = 0;
    904         m_cost_data_tlb_inval_frz = 0;
     901        m_cpt_ins_tlb_inval       = 0;
     902        m_cpt_data_tlb_inval      = 0;
     903        m_cost_ins_tlb_inval_frz  = 0;
     904        m_cost_data_tlb_inval_frz = 0;
    905905
    906906        m_cpt_cc_broadcast   = 0;
    907907
    908             m_cost_updt_data_frz  = 0;
    909             m_cost_inval_ins_frz  = 0;
    910             m_cost_inval_data_frz = 0;
    911             m_cost_broadcast_frz  = 0;
    912 
    913             m_cpt_cc_cleanup_data = 0;
    914             m_cpt_cc_cleanup_ins  = 0;
     908        m_cost_updt_data_frz  = 0;
     909        m_cost_inval_ins_frz  = 0;
     910        m_cost_inval_data_frz = 0;
     911        m_cost_broadcast_frz  = 0;
     912
     913        m_cpt_cc_cleanup_data = 0;
     914        m_cpt_cc_cleanup_ins  = 0;
    915915
    916916        m_cpt_itlbmiss_transaction      = 0;
     
    933933/*
    934934        m_cpt_dcache_frz_cycles = 0;
    935         m_cpt_read              = 0;
    936         m_cpt_write             = 0;
    937             m_cpt_cc_update_data = 0;
    938             m_cpt_cc_inval_ins   = 0;
    939             m_cpt_cc_inval_data  = 0;
     935        m_cpt_read = 0;
     936        m_cpt_write = 0;
     937        m_cpt_cc_update_data = 0;
     938        m_cpt_cc_inval_ins   = 0;
     939        m_cpt_cc_inval_data  = 0;
    940940*/
    941941
    942         for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_icache      [i]  = 0;
    943         for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_dcache      [i]  = 0;
    944         for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_cmd         [i]  = 0;
    945         for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_rsp         [i]  = 0;
     942        for (uint32_t i = 0; i < 32; ++i) m_cpt_fsm_icache[i] = 0;
     943        for (uint32_t i = 0; i < 32; ++i) m_cpt_fsm_dcache[i] = 0;
     944        for (uint32_t i = 0; i < 32; ++i) m_cpt_fsm_cmd[i] = 0;
     945        for (uint32_t i = 0; i < 32; ++i) m_cpt_fsm_rsp[i] = 0;
    946946
    947947        // init the llsc reservation buffer
     
    953953
    954954    // Response FIFOs default values
    955     bool       vci_rsp_fifo_icache_get   = false;
    956     bool       vci_rsp_fifo_icache_put   = false;
    957     uint32_t   vci_rsp_fifo_icache_data = 0;
    958 
    959     bool       vci_rsp_fifo_dcache_get   = false;
    960     bool       vci_rsp_fifo_dcache_put   = false;
    961     uint32_t   vci_rsp_fifo_dcache_data = 0;
     955    bool     vci_rsp_fifo_icache_get  = false;
     956    bool     vci_rsp_fifo_icache_put  = false;
     957    uint32_t vci_rsp_fifo_icache_data = 0;
     958
     959    bool     vci_rsp_fifo_dcache_get  = false;
     960    bool     vci_rsp_fifo_dcache_put  = false;
     961    uint32_t vci_rsp_fifo_dcache_data = 0;
    962962
    963963    // updt fifo
    964     bool       cc_receive_updt_fifo_get  = false;
    965     bool       cc_receive_updt_fifo_put  = false;
    966     uint32_t   cc_receive_updt_fifo_be   = 0;
    967     uint32_t   cc_receive_updt_fifo_data = 0;
    968     bool       cc_receive_updt_fifo_eop  = false;
     964    bool     cc_receive_updt_fifo_get  = false;
     965    bool     cc_receive_updt_fifo_put  = false;
     966    uint32_t cc_receive_updt_fifo_be   = 0;
     967    uint32_t cc_receive_updt_fifo_data = 0;
     968    bool     cc_receive_updt_fifo_eop  = false;
    969969
    970970#ifdef INSTRUMENTATION
    971     m_cpt_fsm_dcache  [r_dcache_fsm.read() ] ++;
    972     m_cpt_fsm_icache  [r_icache_fsm.read() ] ++;
    973     m_cpt_fsm_cmd     [r_vci_cmd_fsm.read()] ++;
    974     m_cpt_fsm_rsp     [r_vci_rsp_fsm.read()] ++;
    975     m_cpt_fsm_tgt     [r_tgt_fsm.read()    ] ++;
    976     m_cpt_fsm_cleanup [r_cleanup_cmd_fsm.read()] ++;
     971    m_cpt_fsm_dcache [r_dcache_fsm.read() ] ++;
     972    m_cpt_fsm_icache [r_icache_fsm.read() ] ++;
     973    m_cpt_fsm_cmd    [r_vci_cmd_fsm.read()] ++;
     974    m_cpt_fsm_rsp    [r_vci_rsp_fsm.read()] ++;
     975    m_cpt_fsm_tgt    [r_tgt_fsm.read()    ] ++;
     976    m_cpt_fsm_cleanup[r_cleanup_cmd_fsm.read()] ++;
    977977#endif
    978978
     
    10451045
    10461046    // default value for m_irsp
    1047     m_irsp.valid       = false;
    1048     m_irsp.error       = false;
     1047    m_irsp.valid = false;
     1048    m_irsp.error = false;
    10491049    m_irsp.instruction = 0;
    10501050
    1051     switch( r_icache_fsm.read() )
     1051    switch (r_icache_fsm.read())
    10521052    {
    10531053    /////////////////
    1054     case ICACHE_IDLE:   // In this state, we handle processor requests, XTN requests,
     1054    case ICACHE_IDLE:   // In this state, we handle processor requests, XTN requests,
    10551055                        // and coherence requests with a fixed priority:
    10561056                        // 1/ Coherence requests                        => ICACHE_CC_CHECK
     
    10611061    {
    10621062        // coherence clack interrupt
    1063         if ( r_icache_clack_req.read() )
     1063        if (r_icache_clack_req.read())
    10641064        {
    10651065            r_icache_fsm = ICACHE_CC_CHECK;
     
    10691069
    10701070        // coherence interrupt
    1071         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
     1071        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
    10721072        {
    10731073            r_icache_fsm = ICACHE_CC_CHECK;
     
    10791079        // These request are not executed in this IDLE state (except XTN_INST_PADDR_EXT),
    10801080        // because they require access to icache or itlb, that are already accessed
    1081         if ( r_dcache_xtn_req.read() )
    1082         {
    1083             if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_PTPR )
    1084             {
    1085                 r_icache_fsm         = ICACHE_XTN_TLB_FLUSH;
    1086             }
    1087             else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ICACHE_FLUSH)
     1081        if (r_dcache_xtn_req.read())
     1082        {
     1083            if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_PTPR )
     1084            {
     1085                r_icache_fsm = ICACHE_XTN_TLB_FLUSH;
     1086            }
     1087            else if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_ICACHE_FLUSH)
    10881088            {
    10891089                r_icache_flush_count = 0;
    1090                 r_icache_fsm         = ICACHE_XTN_CACHE_FLUSH;
    1091             }
    1092             else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ITLB_INVAL)
    1093             {
    1094                 r_icache_fsm         = ICACHE_XTN_TLB_INVAL;
    1095             }
    1096             else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ICACHE_INVAL)
    1097             {
    1098                 r_icache_fsm         = ICACHE_XTN_CACHE_INVAL_VA;
    1099             }
    1100             else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_MMU_ICACHE_PA_INV)
     1090                r_icache_fsm = ICACHE_XTN_CACHE_FLUSH;
     1091            }
     1092            else if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_ITLB_INVAL)
     1093            {
     1094                r_icache_fsm = ICACHE_XTN_TLB_INVAL;
     1095            }
     1096            else if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_ICACHE_INVAL)
     1097            {
     1098                r_icache_fsm = ICACHE_XTN_CACHE_INVAL_VA;
     1099            }
     1100            else if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_MMU_ICACHE_PA_INV)
    11011101            {
    11021102                if (sizeof(paddr_t) <= 32)
     
    11041104                    assert(r_mmu_word_hi.read() == 0 &&
    11051105                    "illegal XTN request in ICACHE: high bits should be 0 for 32bit paddr");
    1106                     r_icache_vci_paddr = (paddr_t)r_mmu_word_lo.read();
     1106                    r_icache_vci_paddr = (paddr_t) r_mmu_word_lo.read();
    11071107                }
    11081108                else
    11091109                {
    1110                     r_icache_vci_paddr = (paddr_t)r_mmu_word_hi.read() << 32 |
    1111                                          (paddr_t)r_mmu_word_lo.read();
     1110                    r_icache_vci_paddr = (paddr_t) r_mmu_word_hi.read() << 32 |
     1111                                         (paddr_t) r_mmu_word_lo.read();
    11121112                }
    11131113                r_icache_fsm = ICACHE_XTN_CACHE_INVAL_PA;
    11141114            }
    1115             else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_INST_PADDR_EXT)
     1115            else if ((int) r_dcache_xtn_opcode.read() == (int) iss_t::XTN_INST_PADDR_EXT)
    11161116            {
    11171117                r_icache_paddr_ext = r_dcache_save_wdata.read();
     
    11201120            else
    11211121            {
    1122                assert( false and
     1122               assert(false and
    11231123               "undefined XTN request received by ICACHE FSM");
    11241124            }
     
    11271127
    11281128        // processor request
    1129         if ( m_ireq.valid )
    1130         {
    1131             bool            cacheable;
    1132             paddr_t         paddr;
    1133             bool        tlb_hit = false;
    1134             pte_info_t  tlb_flags;
    1135             size_t      tlb_way;
    1136             size_t      tlb_set;
    1137             paddr_t     tlb_nline;
    1138             uint32_t    cache_inst = 0;
    1139             size_t      cache_way;
    1140             size_t      cache_set;
    1141             size_t      cache_word;
    1142             int         cache_state = CACHE_SLOT_STATE_EMPTY;
     1129        if (m_ireq.valid )
     1130        {
     1131            bool       cacheable;
     1132            paddr_t    paddr;
     1133            bool       tlb_hit = false;
     1134            pte_info_t tlb_flags;
     1135            size_t     tlb_way;
     1136            size_t     tlb_set;
     1137            paddr_t    tlb_nline;
     1138            uint32_t   cache_inst = 0;
     1139            size_t     cache_way;
     1140            size_t     cache_set;
     1141            size_t     cache_word;
     1142            int        cache_state = CACHE_SLOT_STATE_EMPTY;
    11431143
    11441144            // We register processor request
     
    11471147
    11481148            // sytematic itlb access (if activated)
    1149             if ( r_mmu_mode.read() & INS_TLB_MASK )
     1149            if (r_mmu_mode.read() & INS_TLB_MASK)
    11501150            {
    11511151
    11521152#ifdef INSTRUMENTATION
    1153 m_cpt_itlb_read++;
    1154 #endif
    1155                 tlb_hit = r_itlb.translate( m_ireq.addr,
    1156                                             &paddr,
    1157                                             &tlb_flags,
    1158                                             &tlb_nline, // unused
    1159                                             &tlb_way,   // unused
    1160                                             &tlb_set ); // unused
     1153                m_cpt_itlb_read++;
     1154#endif
     1155                tlb_hit = r_itlb.translate(m_ireq.addr,
     1156                                           &paddr,
     1157                                           &tlb_flags,
     1158                                           &tlb_nline, // unused
     1159                                           &tlb_way,   // unused
     1160                                           &tlb_set); // unused
    11611161            }
    11621162            else if (vci_param::N > 32)
     
    11661166
    11671167            // systematic icache access (if activated)
    1168             if ( r_mmu_mode.read() & INS_CACHE_MASK )
     1168            if (r_mmu_mode.read() & INS_CACHE_MASK)
    11691169            {
    11701170
    11711171
    11721172#ifdef INSTRUMENTATION
    1173 m_cpt_icache_data_read++;
    1174 m_cpt_icache_dir_read++;
    1175 #endif
    1176                 r_icache.read( paddr,
    1177                                &cache_inst,
    1178                                &cache_way,
    1179                                &cache_set,
    1180                                &cache_word,
    1181                                &cache_state );
     1173                m_cpt_icache_data_read++;
     1174                m_cpt_icache_dir_read++;
     1175#endif
     1176                r_icache.read(paddr,
     1177                              &cache_inst,
     1178                              &cache_way,
     1179                              &cache_set,
     1180                              &cache_word,
     1181                              &cache_state);
    11821182            }
    11831183
     
    11881188            //   and there is no access rights checking
    11891189
    1190             if ( not (r_mmu_mode.read() & INS_TLB_MASK) )       // tlb not activated:
     1190            if (not (r_mmu_mode.read() & INS_TLB_MASK)) // tlb not activated:
    11911191            {
    11921192                // cacheability
    1193                 if ( not (r_mmu_mode.read() & INS_CACHE_MASK) ) cacheable = false;
    1194                 else     cacheable = m_cacheability_table[(uint64_t)m_ireq.addr];
    1195             }
    1196             else                                                        // itlb activated
    1197             {
    1198                 if ( tlb_hit )  // ITLB hit
     1193                if   (not (r_mmu_mode.read() & INS_CACHE_MASK)) cacheable = false;
     1194                else cacheable = m_cacheability_table[(uint64_t) m_ireq.addr];
     1195            }
     1196            else // itlb activated
     1197            {
     1198                if (tlb_hit) // ITLB hit
    11991199                {
    12001200                    // cacheability
    1201                     if ( not (r_mmu_mode.read() & INS_CACHE_MASK) ) cacheable = false;
     1201                    if (not (r_mmu_mode.read() & INS_CACHE_MASK)) cacheable = false;
    12021202                    else  cacheable = tlb_flags.c;
    12031203
    12041204                    // access rights checking
    1205                     if ( not tlb_flags.u && (m_ireq.mode == iss_t::MODE_USER) )
     1205                    if (not tlb_flags.u && (m_ireq.mode == iss_t::MODE_USER))
    12061206                    {
    1207                         r_mmu_ietr          = MMU_READ_PRIVILEGE_VIOLATION;
    1208                         r_mmu_ibvar         = m_ireq.addr;
    1209                         m_irsp.valid        = true;
    1210                         m_irsp.error        = true;
    1211                         m_irsp.instruction  = 0;
     1207                        r_mmu_ietr         = MMU_READ_PRIVILEGE_VIOLATION;
     1208                        r_mmu_ibvar        = m_ireq.addr;
     1209                        m_irsp.valid       = true;
     1210                        m_irsp.error       = true;
     1211                        m_irsp.instruction = 0;
    12121212                        break;
    12131213                    }
    1214                     else if ( not tlb_flags.x )
     1214                    else if (not tlb_flags.x)
    12151215                    {
    1216                         r_mmu_ietr          = MMU_READ_EXEC_VIOLATION;
    1217                         r_mmu_ibvar         = m_ireq.addr;
    1218                         m_irsp.valid        = true;
    1219                         m_irsp.error        = true;
    1220                         m_irsp.instruction  = 0;
     1216                        r_mmu_ietr         = MMU_READ_EXEC_VIOLATION;
     1217                        r_mmu_ibvar        = m_ireq.addr;
     1218                        m_irsp.valid       = true;
     1219                        m_irsp.error       = true;
     1220                        m_irsp.instruction = 0;
    12211221                        break;
    12221222                    }
    12231223                }
    1224                 else           // ITLB miss
     1224                else // ITLB miss
    12251225                {
    12261226
    12271227#ifdef INSTRUMENTATION
    1228 m_cpt_itlb_miss++;
     1228                    m_cpt_itlb_miss++;
    12291229#endif
    12301230                    r_icache_fsm          = ICACHE_TLB_WAIT;
     
    12351235
    12361236            // physical address registration
    1237             r_icache_vci_paddr   = paddr;
     1237            r_icache_vci_paddr = paddr;
    12381238
    12391239            // Finally, we send the response to processor, and compute next state
    1240             if ( cacheable )
    1241             {
    1242                 if (cache_state == CACHE_SLOT_STATE_EMPTY)          // cache miss
     1240            if (cacheable)
     1241            {
     1242                if (cache_state == CACHE_SLOT_STATE_EMPTY) // cache miss
    12431243                {
    12441244
    12451245#ifdef INSTRUMENTATION
    1246 m_cpt_icache_miss++;
     1246                    m_cpt_icache_miss++;
    12471247#endif
    12481248                    // we request a VCI transaction
    1249                     r_icache_fsm      = ICACHE_MISS_SELECT;
     1249                    r_icache_fsm = ICACHE_MISS_SELECT;
    12501250#if DEBUG_ICACHE
    1251 if ( m_debug_icache_fsm )
    1252 std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ MISS in icache"
    1253           << " : PADDR = " << std::hex << paddr << std::endl;
     1251                    if (m_debug_icache_fsm)
     1252                        std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ MISS in icache"
     1253                            << " : PADDR = " << std::hex << paddr << std::endl;
    12541254#endif
    12551255                   r_icache_miss_req = true;
    12561256                }
    1257                 else if (cache_state == CACHE_SLOT_STATE_ZOMBI )        // pending cleanup
     1257                else if (cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
    12581258                {
    12591259                    // stalled until cleanup is acknowledged
    1260                     r_icache_fsm       = ICACHE_IDLE;
     1260                    r_icache_fsm = ICACHE_IDLE;
    12611261                }
    1262                 else                                                // cache hit
     1262                else // cache hit
    12631263                {
    12641264
    12651265#ifdef INSTRUMENTATION
    1266 m_cpt_ins_read++;
     1266                    m_cpt_ins_read++;
    12671267#endif
    12681268                    // return instruction to processor
     
    12711271                    r_icache_fsm       = ICACHE_IDLE;
    12721272#if DEBUG_ICACHE
    1273 if ( m_debug_icache_fsm )
    1274 std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ HIT in icache"
    1275           << " : PADDR = " << std::hex << paddr
    1276           << " / INST  = " << cache_inst << std::endl;
     1273                    if (m_debug_icache_fsm)
     1274                        std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ HIT in icache"
     1275                            << " : PADDR = " << std::hex << paddr
     1276                            << " / INST  = " << cache_inst << std::endl;
    12771277#endif
    12781278                }
    12791279            }
    1280             else                // non cacheable read
    1281             {
    1282                 r_icache_unc_req  = true;
    1283                 r_icache_fsm      = ICACHE_UNC_WAIT;
     1280            else // non cacheable read
     1281            {
     1282                r_icache_unc_req = true;
     1283                r_icache_fsm     = ICACHE_UNC_WAIT;
    12841284
    12851285#if DEBUG_ICACHE
    1286 if ( m_debug_icache_fsm )
    1287 {
    1288     std::cout << "  <PROC " << name()
    1289               << " ICACHE_IDLE> READ UNCACHEABLE in icache"
    1290               << " : PADDR = " << std::hex << paddr << std::endl;
    1291 }
     1286                if (m_debug_icache_fsm)
     1287                {
     1288                    std::cout << "  <PROC " << name()
     1289                        << " ICACHE_IDLE> READ UNCACHEABLE in icache"
     1290                        << " : PADDR = " << std::hex << paddr << std::endl;
     1291                }
    12921292#endif
    12931293            }
     
    12961296    }
    12971297    /////////////////////
    1298     case ICACHE_TLB_WAIT:       // Waiting the itlb update by the DCACHE FSM after a tlb miss
     1298    case ICACHE_TLB_WAIT:   // Waiting the itlb update by the DCACHE FSM after a tlb miss
    12991299                            // the itlb is udated by the DCACHE FSM, as well as the
    13001300                            // r_mmu_ietr and r_mmu_ibvar registers in case of error.
     
    13041304    {
    13051305        // coherence clack interrupt
    1306         if ( r_icache_clack_req.read() )
     1306        if (r_icache_clack_req.read())
    13071307        {
    13081308            r_icache_fsm = ICACHE_CC_CHECK;
     
    13121312
    13131313        // coherence interrupt
    1314         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
     1314        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
    13151315        {
    13161316            r_icache_fsm = ICACHE_CC_CHECK;
     
    13191319        }
    13201320
    1321         if ( m_ireq.valid ) m_cost_ins_tlb_miss_frz++;
     1321        if (m_ireq.valid) m_cost_ins_tlb_miss_frz++;
    13221322
    13231323        // DCACHE FSM signals response by reseting the request flip-flop
    1324         if ( not r_icache_tlb_miss_req.read() )
    1325         {
    1326             if ( r_icache_tlb_rsp_error.read() ) // error reported : tlb not updated
     1324        if (not r_icache_tlb_miss_req.read())
     1325        {
     1326            if (r_icache_tlb_rsp_error.read()) // error reported : tlb not updated
    13271327            {
    13281328                r_icache_tlb_rsp_error = false;
    1329                 m_irsp.error             = true;
    1330                 m_irsp.valid             = true;
    1331                 r_icache_fsm             = ICACHE_IDLE;
    1332             }
    1333             else                                // tlb updated : return to IDLE state
     1329                m_irsp.error = true;
     1330                m_irsp.valid = true;
     1331                r_icache_fsm = ICACHE_IDLE;
     1332            }
     1333            else // tlb updated : return to IDLE state
    13341334            {
    13351335                r_icache_fsm  = ICACHE_IDLE;
     
    13391339    }
    13401340    //////////////////////////
    1341     case ICACHE_XTN_TLB_FLUSH:          // invalidate in one cycle all non global TLB entries
     1341    case ICACHE_XTN_TLB_FLUSH:  // invalidate in one cycle all non global TLB entries
    13421342    {
    13431343        r_itlb.flush();
    1344         r_dcache_xtn_req     = false;
    1345         r_icache_fsm         = ICACHE_IDLE;
     1344        r_dcache_xtn_req = false;
     1345        r_icache_fsm     = ICACHE_IDLE;
    13461346        break;
    13471347    }
    13481348    ////////////////////////////
    1349     case ICACHE_XTN_CACHE_FLUSH:        // Invalidate sequencially all cache lines, using
     1349    case ICACHE_XTN_CACHE_FLUSH:    // Invalidate sequencially all cache lines, using
    13501350                                    // r_icache_flush_count as a slot counter,
    1351                                         // looping in this state until all slots are visited.
     1351                                    // looping in this state until all slots are visited.
    13521352                                    // It can require two cycles per slot:
    13531353                                    // We test here the slot state, and make the actual inval
    13541354                                    // (if line is valid) in ICACHE_XTN_CACHE_FLUSH_GO state.
    1355                                         // A cleanup request is generated for each valid line
     1355                                    // A cleanup request is generated for each valid line
    13561356    {
    13571357        // coherence clack interrupt
    1358         if ( r_icache_clack_req.read() )
     1358        if (r_icache_clack_req.read())
    13591359        {
    13601360            r_icache_fsm = ICACHE_CC_CHECK;
     
    13641364
    13651365        // coherence request (from CC_RECEIVE FSM)
    1366         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
     1366        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
    13671367        {
    13681368            r_icache_fsm = ICACHE_CC_CHECK;
     
    13711371        }
    13721372
    1373         if ( not r_icache_cc_send_req.read() ) // blocked until previous cc_send request is sent
    1374         {
    1375             int       state;
    1376             paddr_t   tag;
    1377             size_t        way = r_icache_flush_count.read()/m_icache_sets;
    1378             size_t        set = r_icache_flush_count.read()%m_icache_sets;
     1373        if (not r_icache_cc_send_req.read()) // blocked until previous cc_send request is sent
     1374        {
     1375            int state;
     1376            paddr_t tag;
     1377            size_t way = r_icache_flush_count.read()/m_icache_sets;
     1378            size_t set = r_icache_flush_count.read()%m_icache_sets;
    13791379
    13801380#ifdef INSTRUMENTATION
    1381 m_cpt_icache_dir_read++;
    1382 #endif
    1383             r_icache.read_dir( way,
    1384                                set,
    1385                                &tag,
    1386                                &state );
    1387 
    1388             if ( state == CACHE_SLOT_STATE_VALID )    // inval required
     1381            m_cpt_icache_dir_read++;
     1382#endif
     1383            r_icache.read_dir(way,
     1384                              set,
     1385                              &tag,
     1386                              &state);
     1387
     1388            if (state == CACHE_SLOT_STATE_VALID)    // inval required
    13891389            {
    13901390                // request cleanup
     
    13951395
    13961396                // goes to ICACHE_XTN_CACHE_FLUSH_GO to make inval
    1397                 r_icache_miss_way     = way;
    1398                 r_icache_miss_set     = set;
    1399                 r_icache_fsm          = ICACHE_XTN_CACHE_FLUSH_GO;
    1400             }
    1401             else if ( r_icache_flush_count.read() ==
    1402                       (m_icache_sets*m_icache_ways - 1) )  // last slot
    1403             {
    1404                 r_dcache_xtn_req = false;
    1405                 m_drsp.valid     = true;
    1406                 r_icache_fsm    = ICACHE_IDLE;
     1397                r_icache_miss_way = way;
     1398                r_icache_miss_set = set;
     1399                r_icache_fsm      = ICACHE_XTN_CACHE_FLUSH_GO;
     1400            }
     1401            else if (r_icache_flush_count.read() ==
     1402                      (m_icache_sets*m_icache_ways - 1))  // last slot
     1403            {
     1404                r_dcache_xtn_req = false;
     1405                m_drsp.valid = true;
     1406                r_icache_fsm = ICACHE_IDLE;
    14071407            }
    14081408
    14091409            // saturation counter, to have the same last slot condition
    14101410            // in ICACHE_XTN_CACHE_FLUSH and ICACHE_XTN_CACHE_FLUSH_GO states
    1411             if ( r_icache_flush_count.read() < (m_icache_sets*m_icache_ways - 1) )
     1411            if (r_icache_flush_count.read() < (m_icache_sets * m_icache_ways - 1))
    14121412            {
    14131413                r_icache_flush_count = r_icache_flush_count.read() + 1;
     
    14171417    }
    14181418    ///////////////////////////////
    1419     case ICACHE_XTN_CACHE_FLUSH_GO:         // Switch slot state to ZOMBI for an XTN flush
    1420     {
    1421         size_t    way = r_icache_miss_way.read();
    1422         size_t    set = r_icache_miss_set.read();
     1419    case ICACHE_XTN_CACHE_FLUSH_GO:   // Switch slot state to ZOMBI for an XTN flush
     1420    {
     1421        size_t way = r_icache_miss_way.read();
     1422        size_t set = r_icache_miss_set.read();
    14231423
    14241424#ifdef INSTRUMENTATION
    1425 m_cpt_icache_dir_write++;
    1426 #endif
    1427 
    1428         r_icache.write_dir( way,
    1429                             set,
    1430                             CACHE_SLOT_STATE_ZOMBI );
    1431 
    1432         if ( r_icache_flush_count.read() ==
    1433                       (m_icache_sets*m_icache_ways - 1) )  // last slot
    1434         {
    1435                 r_dcache_xtn_req = false;
    1436             m_drsp.valid     = true;
    1437                 r_icache_fsm    = ICACHE_IDLE;
     1425        m_cpt_icache_dir_write++;
     1426#endif
     1427
     1428        r_icache.write_dir(way,
     1429                           set,
     1430                           CACHE_SLOT_STATE_ZOMBI);
     1431
     1432        if (r_icache_flush_count.read() ==
     1433                      (m_icache_sets*m_icache_ways - 1))  // last slot
     1434        {
     1435            r_dcache_xtn_req = false;
     1436            m_drsp.valid = true;
     1437            r_icache_fsm = ICACHE_IDLE;
    14381438        }
    14391439        else
    14401440        {
    1441             r_icache_fsm         = ICACHE_XTN_CACHE_FLUSH;
     1441            r_icache_fsm = ICACHE_XTN_CACHE_FLUSH;
    14421442        }
    14431443        break;
     
    14451445
    14461446    //////////////////////////
    1447     case ICACHE_XTN_TLB_INVAL:          // invalidate one TLB entry selected by the virtual address
    1448                                                     // stored in the r_dcache_save_wdata register
     1447    case ICACHE_XTN_TLB_INVAL: // invalidate one TLB entry selected by the virtual address
     1448                               // stored in the r_dcache_save_wdata register
    14491449    {
    14501450        r_itlb.inval(r_dcache_save_wdata.read());
    1451         r_dcache_xtn_req     = false;
    1452         r_icache_fsm         = ICACHE_IDLE;
     1451        r_dcache_xtn_req = false;
     1452        r_icache_fsm     = ICACHE_IDLE;
    14531453        break;
    14541454    }
    14551455    ///////////////////////////////
    1456     case ICACHE_XTN_CACHE_INVAL_VA:     // Selective cache line invalidate with virtual address
     1456    case ICACHE_XTN_CACHE_INVAL_VA: // Selective cache line invalidate with virtual address
    14571457                                    // requires 3 cycles (in case of hit on itlb and icache).
    1458                                                         // In this state, access TLB to translate virtual address
    1459                                                     // stored in the r_dcache_save_wdata register.
    1460     {
    1461         paddr_t         paddr;
    1462         bool            hit;
     1458                                    // In this state, access TLB to translate virtual address
     1459                                    // stored in the r_dcache_save_wdata register.
     1460    {
     1461        paddr_t paddr;
     1462        bool    hit;
    14631463
    14641464        // read physical address in TLB when MMU activated
    1465         if ( r_mmu_mode.read() & INS_TLB_MASK )         // itlb activated
     1465        if (r_mmu_mode.read() & INS_TLB_MASK) // itlb activated
    14661466        {
    14671467
    14681468#ifdef INSTRUMENTATION
    1469 m_cpt_itlb_read++;
    1470 #endif
    1471             hit = r_itlb.translate(r_dcache_save_wdata.read(),
    1472                                    &paddr);
    1473         }
    1474         else                                            // itlb not activated
    1475         {
    1476             paddr       = (paddr_t)r_dcache_save_wdata.read();
    1477             hit         = true;
    1478         }
    1479 
    1480         if ( hit )              // continue the selective inval process
    1481         {
    1482             r_icache_vci_paddr    = paddr;
    1483             r_icache_fsm          = ICACHE_XTN_CACHE_INVAL_PA;
    1484         }
    1485         else                    // miss : send a request to DCACHE FSM
     1469            m_cpt_itlb_read++;
     1470#endif
     1471            hit = r_itlb.translate(r_dcache_save_wdata.read(), &paddr);
     1472        }
     1473        else // itlb not activated
     1474        {
     1475            paddr = (paddr_t) r_dcache_save_wdata.read();
     1476            hit   = true;
     1477        }
     1478
     1479        if (hit) // continue the selective inval process
     1480        {
     1481            r_icache_vci_paddr = paddr;
     1482            r_icache_fsm       = ICACHE_XTN_CACHE_INVAL_PA;
     1483        }
     1484        else // miss : send a request to DCACHE FSM
    14861485        {
    14871486
    14881487#ifdef INSTRUMENTATION
    1489 m_cpt_itlb_miss++;
     1488            m_cpt_itlb_miss++;
    14901489#endif
    14911490            r_icache_tlb_miss_req = true;
    1492                 r_icache_vaddr_save   = r_dcache_save_wdata.read();
     1491            r_icache_vaddr_save   = r_dcache_save_wdata.read();
    14931492            r_icache_fsm          = ICACHE_TLB_WAIT;
    14941493        }
     
    14961495    }
    14971496    ///////////////////////////////
    1498     case ICACHE_XTN_CACHE_INVAL_PA:     // selective invalidate cache line with physical address
     1497    case ICACHE_XTN_CACHE_INVAL_PA: // selective invalidate cache line with physical address
    14991498                                    // require 2 cycles. In this state, we read directory
    15001499                                    // with address stored in r_icache_vci_paddr register.
    15011500    {
    1502         int         state;
    1503         size_t          way;
    1504         size_t          set;
    1505         size_t          word;
     1501        int    state;
     1502        size_t way;
     1503        size_t set;
     1504        size_t word;
    15061505
    15071506#ifdef INSTRUMENTATION
    1508 m_cpt_icache_dir_read++;
     1507        m_cpt_icache_dir_read++;
    15091508#endif
    15101509        r_icache.read_dir(r_icache_vci_paddr.read(),
     
    15141513                          &word);
    15151514
    1516         if ( state == CACHE_SLOT_STATE_VALID )  // inval to be done
     1515        if (state == CACHE_SLOT_STATE_VALID) // inval to be done
    15171516        {
    15181517            r_icache_miss_way = way;
     
    15201519            r_icache_fsm      = ICACHE_XTN_CACHE_INVAL_GO;
    15211520        }
    1522         else            // miss : acknowlege the XTN request and return
     1521        else // miss : acknowlege the XTN request and return
    15231522        {
    15241523            r_dcache_xtn_req = false;
     
    15301529    case ICACHE_XTN_CACHE_INVAL_GO:  // Switch slot to ZOMBI state for an XTN inval
    15311530    {
    1532         if ( not r_icache_cc_send_req.read() )  // blocked until previous cc_send request not sent
     1531        if (not r_icache_cc_send_req.read())  // blocked until previous cc_send request not sent
    15331532        {
    15341533
    15351534#ifdef INSTRUMENTATION
    1536 m_cpt_icache_dir_write++;
    1537 #endif
    1538             r_icache.write_dir( r_icache_miss_way.read(),
    1539                                 r_icache_miss_set.read(),
    1540                                 CACHE_SLOT_STATE_ZOMBI );
     1535            m_cpt_icache_dir_write++;
     1536#endif
     1537            r_icache.write_dir(r_icache_miss_way.read(),
     1538                               r_icache_miss_set.read(),
     1539                               CACHE_SLOT_STATE_ZOMBI);
    15411540
    15421541            // request cleanup
    15431542            r_icache_cc_send_req   = true;
    1544             r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words<<2);
     1543            r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words << 2);
    15451544            r_icache_cc_send_way   = r_icache_miss_way.read();
    15461545            r_icache_cc_send_type  = CC_TYPE_CLEANUP;
    15471546
    15481547            // acknowledge the XTN request and return
    1549             r_dcache_xtn_req      = false;
    1550             r_icache_fsm          = ICACHE_IDLE;
     1548            r_dcache_xtn_req = false;
     1549            r_icache_fsm     = ICACHE_IDLE;
    15511550        }
    15521551        break;
     
    15661565
    15671566        // coherence clack interrupt
    1568         if ( r_icache_clack_req.read() )
     1567        if (r_icache_clack_req.read())
    15691568        {
    15701569            r_icache_fsm = ICACHE_CC_CHECK;
     
    15741573
    15751574        // coherence interrupt
    1576         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
     1575        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
    15771576        {
    15781577            r_icache_fsm = ICACHE_CC_CHECK;
     
    15821581
    15831582
    1584         bool        found;
    1585         bool        cleanup;
    1586         size_t          way;
    1587         size_t          set;
    1588         paddr_t         victim;
     1583        bool found;
     1584        bool cleanup;
     1585        size_t way;
     1586        size_t set;
     1587        paddr_t victim;
    15891588
    15901589#ifdef INSTRUMENTATION
    1591 m_cpt_icache_dir_read++;
     1590        m_cpt_icache_dir_read++;
    15921591#endif
    15931592        r_icache.read_select(r_icache_vci_paddr.read(),
     
    15961595                             &set,
    15971596                             &found,
    1598                              &cleanup );
    1599         if ( not found )
     1597                             &cleanup);
     1598        if (not found)
    16001599        {
    16011600            break;
     
    16031602        else
    16041603        {
    1605             r_icache_miss_way     = way;
    1606             r_icache_miss_set     = set;
    1607 
    1608             if ( cleanup )
    1609             {
    1610                 if ( not r_icache_cc_send_req.read() )
     1604            r_icache_miss_way = way;
     1605            r_icache_miss_set = set;
     1606
     1607            if (cleanup)
     1608            {
     1609                if (not r_icache_cc_send_req.read())
    16111610                {
    1612                     r_icache_cc_send_req    = true;
    1613                     r_icache_cc_send_nline  = victim;
    1614                     r_icache_cc_send_way    = way;
    1615                     r_icache_cc_send_type   = CC_TYPE_CLEANUP;   
     1611                    r_icache_cc_send_req   = true;
     1612                    r_icache_cc_send_nline = victim;
     1613                    r_icache_cc_send_way   = way;
     1614                    r_icache_cc_send_type  = CC_TYPE_CLEANUP;   
    16161615                }
    16171616                else
     
    16211620                }
    16221621
    1623                 r_icache_miss_clack           = true;
    1624                 r_icache_fsm                  = ICACHE_MISS_CLEAN;
     1622                r_icache_miss_clack = true;
     1623                r_icache_fsm        = ICACHE_MISS_CLEAN;
    16251624            }
    16261625            else
    16271626            {
    1628                 r_icache_fsm          = ICACHE_MISS_WAIT;
     1627                r_icache_fsm = ICACHE_MISS_WAIT;
    16291628            }
    16301629
    16311630#if DEBUG_ICACHE
    1632 if ( m_debug_icache_fsm )
    1633 {
    1634     std::cout << "  <PROC " << name()
    1635               << " ICACHE_MISS_SELECT> Select a slot:" << std::dec
    1636               << " / WAY = " << way
    1637               << " / SET = " << set;
    1638     if (cleanup) std::cout << " / VICTIM = " << std::hex << victim << std::endl;
    1639     else         std::cout << std::endl;
    1640 }
     1631            if (m_debug_icache_fsm)
     1632            {
     1633                std::cout << "  <PROC " << name()
     1634                    << " ICACHE_MISS_SELECT> Select a slot:" << std::dec
     1635                    << " / WAY = " << way
     1636                    << " / SET = " << set;
     1637                if (cleanup) std::cout << " / VICTIM = " << std::hex << victim << std::endl;
     1638                else         std::cout << std::endl;
     1639            }
    16411640#endif
    16421641        }
     
    16441643    }
    16451644    ///////////////////////
    1646     case ICACHE_MISS_CLEAN:              // switch the slot to zombi state
     1645    case ICACHE_MISS_CLEAN:   // switch the slot to zombi state
    16471646    {
    16481647        if (m_ireq.valid) m_cost_ins_miss_frz++;
    16491648
    16501649#ifdef INSTRUMENTATION
    1651 m_cpt_icache_dir_write++;
    1652 #endif
    1653         r_icache.write_dir( r_icache_miss_way.read(),
    1654                             r_icache_miss_set.read(),
    1655                             CACHE_SLOT_STATE_ZOMBI);
     1650        m_cpt_icache_dir_write++;
     1651#endif
     1652        r_icache.write_dir(r_icache_miss_way.read(),
     1653                           r_icache_miss_set.read(),
     1654                           CACHE_SLOT_STATE_ZOMBI);
    16561655#if DEBUG_ICACHE
    1657 if ( m_debug_icache_fsm )
    1658 {
    1659     std::cout << "  <PROC " << name()
    1660               << " ICACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
    1661               << " / WAY = " << r_icache_miss_way.read()
    1662               << " / SET = " << r_icache_miss_set.read() << std::endl;
    1663 }
     1656        if (m_debug_icache_fsm)
     1657        {
     1658            std::cout << "  <PROC " << name()
     1659                << " ICACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
     1660                << " / WAY = " << r_icache_miss_way.read()
     1661                << " / SET = " << r_icache_miss_set.read() << std::endl;
     1662        }
    16641663#endif
    16651664
     
    16681667    }
    16691668    //////////////////////
    1670     case ICACHE_MISS_WAIT:        // waiting response from VCI_RSP FSM
     1669    case ICACHE_MISS_WAIT: // waiting response from VCI_RSP FSM
    16711670    {
    16721671        if (m_ireq.valid) m_cost_ins_miss_frz++;
    16731672
    16741673        // send cleanup victim request
    1675         if ( r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read() )
     1674        if (r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read())
    16761675        {
    16771676            r_icache_cc_send_req        = true;
     
    16831682
    16841683        // coherence clack interrupt
    1685         if ( r_icache_clack_req.read() )
     1684        if (r_icache_clack_req.read())
    16861685        {
    16871686            r_icache_fsm = ICACHE_CC_CHECK;
     
    16911690       
    16921691        // coherence interrupt
    1693         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read() )
     1692        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read())
    16941693        {
    16951694            r_icache_fsm = ICACHE_CC_CHECK;
     
    16981697        }
    16991698
    1700         if ( r_vci_rsp_ins_error.read() ) // bus error
     1699        if (r_vci_rsp_ins_error.read()) // bus error
    17011700        {
    17021701            r_mmu_ietr          = MMU_READ_DATA_ILLEGAL_ACCESS;
     
    17071706            r_icache_fsm        = ICACHE_IDLE;
    17081707        }
    1709         else if ( r_vci_rsp_fifo_icache.rok() ) // response available
     1708        else if (r_vci_rsp_fifo_icache.rok()) // response available
    17101709        {
    17111710            r_icache_miss_word = 0;
     
    17151714    }
    17161715    ///////////////////////////
    1717     case ICACHE_MISS_DATA_UPDT:   // update the cache (one word per cycle)
    1718     {
    1719         if ( m_ireq.valid ) m_cost_ins_miss_frz++;
    1720 
    1721         if ( r_vci_rsp_fifo_icache.rok() )      // response available
     1716    case ICACHE_MISS_DATA_UPDT:  // update the cache (one word per cycle)
     1717    {
     1718        if (m_ireq.valid) m_cost_ins_miss_frz++;
     1719
     1720        if (r_vci_rsp_fifo_icache.rok()) // response available
    17221721        {
    17231722
    17241723#ifdef INSTRUMENTATION
    1725 m_cpt_icache_data_write++;
    1726 #endif
    1727             r_icache.write( r_icache_miss_way.read(),
    1728                             r_icache_miss_set.read(),
    1729                             r_icache_miss_word.read(),
    1730                             r_vci_rsp_fifo_icache.read() );
     1724            m_cpt_icache_data_write++;
     1725#endif
     1726            r_icache.write(r_icache_miss_way.read(),
     1727                           r_icache_miss_set.read(),
     1728                           r_icache_miss_word.read(),
     1729                           r_vci_rsp_fifo_icache.read());
    17311730#if DEBUG_ICACHE
    1732 if ( m_debug_icache_fsm )
    1733 {
    1734     std::cout << "  <PROC " << name()
    1735               << " ICACHE_MISS_DATA_UPDT> Write one word:"
    1736               << " WDATA = " << std::hex << r_vci_rsp_fifo_icache.read()
    1737               << " WAY = " << r_icache_miss_way.read()
    1738               << " SET = " << r_icache_miss_set.read()
    1739               << " WORD = " << r_icache_miss_word.read() << std::endl;
    1740 }
     1731            if (m_debug_icache_fsm)
     1732            {
     1733                std::cout << "  <PROC " << name()
     1734                    << " ICACHE_MISS_DATA_UPDT> Write one word:"
     1735                    << " WDATA = " << std::hex << r_vci_rsp_fifo_icache.read()
     1736                    << " WAY = " << r_icache_miss_way.read()
     1737                    << " SET = " << r_icache_miss_set.read()
     1738                    << " WORD = " << r_icache_miss_word.read() << std::endl;
     1739            }
    17411740#endif
    17421741            vci_rsp_fifo_icache_get = true;
    17431742            r_icache_miss_word = r_icache_miss_word.read() + 1;
    17441743
    1745             if ( r_icache_miss_word.read() == m_icache_words-1 )        // last word
     1744            if (r_icache_miss_word.read() == m_icache_words - 1) // last word
    17461745            {
    17471746                r_icache_fsm = ICACHE_MISS_DIR_UPDT;
     
    17511750    }
    17521751    //////////////////////////
    1753     case ICACHE_MISS_DIR_UPDT:  // Stalled if a victim line has been evicted,
     1752    case ICACHE_MISS_DIR_UPDT:  // Stalled if a victim line has been evicted,
    17541753                                // and the cleanup ack has not been received,
    17551754                                // as indicated by r_icache_miss_clack.
     
    17591758                                //   to ZOMBI state, and send a cleanup request.
    17601759    {
    1761         if ( m_ireq.valid ) m_cost_ins_miss_frz++;
     1760        if (m_ireq.valid ) m_cost_ins_miss_frz++;
    17621761
    17631762        // send cleanup victim request
    1764         if ( r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read() )
     1763        if (r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read())
    17651764        {
    17661765            r_icache_cc_send_req        = true;
     
    17721771
    17731772        // coherence clack interrupt
    1774         if ( r_icache_clack_req.read() )
     1773        if (r_icache_clack_req.read())
    17751774        {
    17761775            r_icache_fsm = ICACHE_CC_CHECK;
     
    17801779
    17811780        // coherence interrupt
    1782         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read() )
     1781        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read())
    17831782        {
    17841783            r_icache_fsm = ICACHE_CC_CHECK;
     
    17871786        }
    17881787
    1789         if ( not r_icache_miss_clack.read() ) // waiting cleanup acknowledge for victim line
    1790         {
    1791             if ( r_icache_miss_inval )    // Switch slot to ZOMBI state, and new cleanup
    1792             {
    1793                 if ( not r_icache_cc_send_req.read() )
     1788        if (not r_icache_miss_clack.read()) // waiting cleanup acknowledge for victim line
     1789        {
     1790            if (r_icache_miss_inval) // Switch slot to ZOMBI state, and new cleanup
     1791            {
     1792                if (not r_icache_cc_send_req.read())
    17941793                {
    17951794                    r_icache_miss_inval    = false;
    17961795                    // request cleanup
    17971796                    r_icache_cc_send_req   = true;
    1798                     r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words<<2);
     1797                    r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words << 2);
    17991798                    r_icache_cc_send_way   = r_icache_miss_way.read();
    18001799                    r_icache_cc_send_type  = CC_TYPE_CLEANUP;
    18011800
    18021801#ifdef INSTRUMENTATION
    1803 m_cpt_icache_dir_write++;
    1804 #endif
    1805                     r_icache.write_dir( r_icache_vci_paddr.read(),
    1806                                         r_icache_miss_way.read(),
    1807                                         r_icache_miss_set.read(),
    1808                                         CACHE_SLOT_STATE_ZOMBI );
     1802                    m_cpt_icache_dir_write++;
     1803#endif
     1804                    r_icache.write_dir(r_icache_vci_paddr.read(),
     1805                                       r_icache_miss_way.read(),
     1806                                       r_icache_miss_set.read(),
     1807                                       CACHE_SLOT_STATE_ZOMBI);
    18091808#if DEBUG_ICACHE
    1810 if ( m_debug_icache_fsm )
    1811 {
    1812     std::cout << "  <PROC " << name()
    1813               << " ICACHE_MISS_DIR_UPDT> Switch cache slot to ZOMBI state"
    1814               << " PADDR = " << std::hex << r_icache_vci_paddr.read()
    1815               << " WAY = " << std::dec << r_icache_miss_way.read()
    1816               << " SET = " << r_icache_miss_set.read() << std::endl;
    1817 }
     1809                    if (m_debug_icache_fsm)
     1810                    {
     1811                        std::cout << "  <PROC " << name()
     1812                            << " ICACHE_MISS_DIR_UPDT> Switch cache slot to ZOMBI state"
     1813                            << " PADDR = " << std::hex << r_icache_vci_paddr.read()
     1814                            << " WAY = " << std::dec << r_icache_miss_way.read()
     1815                            << " SET = " << r_icache_miss_set.read() << std::endl;
     1816                    }
    18181817#endif
    18191818                }
     
    18211820                    break;
    18221821            }
    1823             else                          // Switch slot to VALID state
     1822            else // Switch slot to VALID state
    18241823            {
    18251824
    18261825#ifdef INSTRUMENTATION
    1827 m_cpt_icache_dir_write++;
    1828 #endif
    1829                 r_icache.write_dir( r_icache_vci_paddr.read(),
    1830                                     r_icache_miss_way.read(),
    1831                                     r_icache_miss_set.read(),
    1832                                     CACHE_SLOT_STATE_VALID );
     1826                m_cpt_icache_dir_write++;
     1827#endif
     1828                r_icache.write_dir(r_icache_vci_paddr.read(),
     1829                                   r_icache_miss_way.read(),
     1830                                   r_icache_miss_set.read(),
     1831                                   CACHE_SLOT_STATE_VALID);
    18331832#if DEBUG_ICACHE
    1834 if ( m_debug_icache_fsm )
    1835 {
    1836     std::cout << "  <PROC " << name()
    1837               << " ICACHE_MISS_DIR_UPDT> Switch cache slot to VALID state"
    1838               << " PADDR = " << std::hex << r_icache_vci_paddr.read()
    1839               << " WAY = " << std::dec << r_icache_miss_way.read()
    1840               << " SET = " << r_icache_miss_set.read() << std::endl;
    1841 }
     1833                if (m_debug_icache_fsm)
     1834                {
     1835                    std::cout << "  <PROC " << name()
     1836                        << " ICACHE_MISS_DIR_UPDT> Switch cache slot to VALID state"
     1837                        << " PADDR = " << std::hex << r_icache_vci_paddr.read()
     1838                        << " WAY = " << std::dec << r_icache_miss_way.read()
     1839                        << " SET = " << r_icache_miss_set.read() << std::endl;
     1840                }
    18421841#endif
    18431842            }
     
    18481847    }
    18491848    ////////////////////
    1850     case ICACHE_UNC_WAIT:       // waiting a response to an uncacheable read from VCI_RSP FSM
     1849    case ICACHE_UNC_WAIT: // waiting a response to an uncacheable read from VCI_RSP FSM
    18511850    {
    18521851        // coherence clack interrupt
    1853         if ( r_icache_clack_req.read() )
    1854         {
    1855             r_icache_fsm = ICACHE_CC_CHECK;
     1852        if (r_icache_clack_req.read())
     1853        {
     1854            r_icache_fsm      = ICACHE_CC_CHECK;
    18561855            r_icache_fsm_save = r_icache_fsm.read();
    18571856            break;
     
    18591858
    18601859        // coherence interrupt
    1861         if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
    1862         {
    1863             r_icache_fsm = ICACHE_CC_CHECK;
     1860        if (r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
     1861        {
     1862            r_icache_fsm      = ICACHE_CC_CHECK;
    18641863            r_icache_fsm_save = r_icache_fsm.read();
    18651864            break;
    18661865        }
    18671866
    1868         if ( r_vci_rsp_ins_error.read() ) // bus error
     1867        if (r_vci_rsp_ins_error.read()) // bus error
    18691868        {
    18701869            r_mmu_ietr          = MMU_READ_DATA_ILLEGAL_ACCESS;
     
    18751874            r_icache_fsm        = ICACHE_IDLE;
    18761875        }
    1877         else if (r_vci_rsp_fifo_icache.rok() ) // instruction available
     1876        else if (r_vci_rsp_fifo_icache.rok()) // instruction available
    18781877        {
    18791878            vci_rsp_fifo_icache_get = true;
    18801879            r_icache_fsm            = ICACHE_IDLE;
    1881             if ( m_ireq.valid and
    1882                 (m_ireq.addr == r_icache_vaddr_save.read()) ) // request unmodified
     1880            if (m_ireq.valid and
     1881                (m_ireq.addr == r_icache_vaddr_save.read())) // request unmodified
    18831882            {
    18841883                m_irsp.valid       = true;
     
    18891888    }
    18901889    /////////////////////
    1891     case ICACHE_CC_CHECK:       // This state is the entry point of a sub-fsm
    1892                                 // handling coherence requests.
    1893                                 // if there is a matching pending miss, it is
    1894                                 // signaled in the r_icache_miss_inval flip-flop.
    1895                                 // The return state is defined in r_icache_fsm_save.
    1896     {
    1897         paddr_t  paddr = r_cc_receive_icache_nline.read() * m_icache_words * 4;
    1898         paddr_t  mask  = ~((m_icache_words<<2)-1);
     1890    case ICACHE_CC_CHECK:   // This state is the entry point of a sub-fsm
     1891                            // handling coherence requests.
     1892                            // if there is a matching pending miss, it is
     1893                            // signaled in the r_icache_miss_inval flip-flop.
     1894                            // The return state is defined in r_icache_fsm_save.
     1895    {
     1896        paddr_t paddr = r_cc_receive_icache_nline.read() * m_icache_words * 4;
     1897        paddr_t mask  = ~((m_icache_words << 2) - 1);
    18991898
    19001899        // CLACK handler
     
    19021901        // and reset r_icache_miss_clack if the cleanup ack
    19031902        // is matching a pending miss.
    1904         if ( r_icache_clack_req.read() )
    1905         {
    1906 
    1907             if ( m_ireq.valid ) m_cost_ins_miss_frz++;
     1903        if (r_icache_clack_req.read())
     1904        {
     1905
     1906            if (m_ireq.valid) m_cost_ins_miss_frz++;
    19081907
    19091908#ifdef INSTRUMENTATION
    1910 m_cpt_icache_dir_write++;
    1911 #endif
    1912             r_icache.write_dir( 0,
    1913                                 r_icache_clack_way.read(),
    1914                                 r_icache_clack_set.read(),
    1915                                 CACHE_SLOT_STATE_EMPTY);
    1916 
    1917             if ( (r_icache_miss_set.read() == r_icache_clack_set.read()) and
    1918                  (r_icache_miss_way.read() == r_icache_clack_way.read()) )
     1909            m_cpt_icache_dir_write++;
     1910#endif
     1911            r_icache.write_dir(0,
     1912                               r_icache_clack_way.read(),
     1913                               r_icache_clack_set.read(),
     1914                               CACHE_SLOT_STATE_EMPTY);
     1915
     1916            if ((r_icache_miss_set.read() == r_icache_clack_set.read()) and
     1917                 (r_icache_miss_way.read() == r_icache_clack_way.read()))
    19191918            {
    19201919                r_icache_miss_clack = false;
     
    19271926
    19281927#if DEBUG_ICACHE
    1929 if ( m_debug_icache_fsm )
    1930 {
    1931     std::cout << "  <PROC " << name()
    1932         << " ICACHE_CC_CHECK>  CC_TYPE_CLACK slot returns to empty state"
    1933         << " set = " << r_icache_clack_set.read()
    1934         << " / way = " << r_icache_clack_way.read() << std::endl;
    1935 }
    1936 #endif
    1937 
    1938             break;
    1939         }
    1940 
    1941         assert ( not r_icache_cc_send_req.read() and "CC_SEND must be available in ICACHE_CC_CHECK");
     1928            if (m_debug_icache_fsm)
     1929            {
     1930                std::cout << "  <PROC " << name()
     1931                    << " ICACHE_CC_CHECK>  CC_TYPE_CLACK slot returns to empty state"
     1932                    << " set = " << r_icache_clack_set.read()
     1933                    << " / way = " << r_icache_clack_way.read() << std::endl;
     1934            }
     1935#endif
     1936
     1937            break;
     1938        }
     1939
     1940        assert(not r_icache_cc_send_req.read() and "CC_SEND must be available in ICACHE_CC_CHECK");
    19421941
    19431942        // Match between MISS address and CC address
    19441943        if (r_cc_receive_icache_req.read() and
    1945           ((r_icache_fsm_save.read() == ICACHE_MISS_SELECT  )  or
    1946            (r_icache_fsm_save.read() == ICACHE_MISS_WAIT    )  or
     1944          ((r_icache_fsm_save.read() == ICACHE_MISS_SELECT)  or
     1945           (r_icache_fsm_save.read() == ICACHE_MISS_WAIT)  or
    19471946           (r_icache_fsm_save.read() == ICACHE_MISS_DIR_UPDT)) and
    1948           ((r_icache_vci_paddr.read() & mask) == (paddr & mask)) ) // matching
     1947          ((r_icache_vci_paddr.read() & mask) == (paddr & mask))) // matching
    19491948        {
    19501949            // signaling the matching
    1951             r_icache_miss_inval     = true;
     1950            r_icache_miss_inval = true;
    19521951
    19531952            // in case of update, go to CC_UPDT
     
    19551954            if (r_cc_receive_icache_type.read() == CC_TYPE_UPDT)
    19561955            {
    1957                 r_icache_fsm        = ICACHE_CC_UPDT;
    1958                 r_icache_cc_word    = r_cc_receive_word_idx.read();
     1956                r_icache_fsm = ICACHE_CC_UPDT;
     1957                r_icache_cc_word = r_cc_receive_word_idx.read();
    19591958
    19601959                // just pop the fifo , don't write in icache
     
    19651964            {
    19661965                r_cc_receive_icache_req = false;
    1967                 r_icache_fsm          = r_icache_fsm_save.read();
     1966                r_icache_fsm = r_icache_fsm_save.read();
    19681967            }
    19691968#if DEBUG_ICACHE
    1970 if ( m_debug_icache_fsm )
    1971 {
    1972     std::cout << "  <PROC " << name()
    1973               << " ICACHE_CC_CHECK> Coherence request matching a pending miss:"
    1974               << " PADDR = " << std::hex << paddr << std::endl;
    1975 }
     1969            if (m_debug_icache_fsm)
     1970            {
     1971                std::cout << "  <PROC " << name()
     1972                    << " ICACHE_CC_CHECK> Coherence request matching a pending miss:"
     1973                    << " PADDR = " << std::hex << paddr << std::endl;
     1974            }
    19761975#endif
    19771976        }
     
    19791978        // CC request handler
    19801979
    1981         int             state = 0;
    1982         size_t      way = 0;
    1983         size_t      set = 0;
    1984         size_t      word = 0;
     1980        int    state = 0;
     1981        size_t way = 0;
     1982        size_t set = 0;
     1983        size_t word = 0;
    19851984
    19861985#ifdef INSTRUMENTATION
    1987 m_cpt_icache_dir_read++;
     1986        m_cpt_icache_dir_read++;
    19881987#endif
    19891988        r_icache.read_dir(paddr,
     
    19961995        r_icache_cc_set = set;
    19971996
    1998         if ( state == CACHE_SLOT_STATE_VALID)            // hit
     1997        if (state == CACHE_SLOT_STATE_VALID)            // hit
    19991998        {
    20001999            // need to update the cache state
     
    20022001            {
    20032002                r_icache_cc_need_write = true;
    2004                 r_icache_fsm           = ICACHE_CC_UPDT;
    2005                 r_icache_cc_word       = r_cc_receive_word_idx.read();
    2006             }
    2007             else if ( r_cc_receive_icache_type.read() == CC_TYPE_INVAL ) // hit inval
    2008             {
    2009                 r_icache_fsm           = ICACHE_CC_INVAL;
     2003                r_icache_fsm = ICACHE_CC_UPDT;
     2004                r_icache_cc_word = r_cc_receive_word_idx.read();
     2005            }
     2006            else if (r_cc_receive_icache_type.read() == CC_TYPE_INVAL) // hit inval
     2007            {
     2008                r_icache_fsm = ICACHE_CC_INVAL;
    20102009            }
    20112010        }
     
    20132012        {
    20142013            // multicast acknowledgement required in case of update
    2015             if(r_cc_receive_icache_type.read() == CC_TYPE_UPDT)
    2016             {
    2017                 r_icache_fsm           = ICACHE_CC_UPDT;
    2018                 r_icache_cc_word       = r_cc_receive_word_idx.read();
     2014            if (r_cc_receive_icache_type.read() == CC_TYPE_UPDT)
     2015            {
     2016                r_icache_fsm = ICACHE_CC_UPDT;
     2017                r_icache_cc_word = r_cc_receive_word_idx.read();
    20192018
    20202019                // just pop the fifo , don't write in icache
     
    20242023            {
    20252024                r_cc_receive_icache_req = false;
    2026                 r_icache_fsm            = r_icache_fsm_save.read();
     2025                r_icache_fsm = r_icache_fsm_save.read();
    20272026            }
    20282027        }
     
    20302029    }
    20312030    /////////////////////
    2032     case ICACHE_CC_INVAL:       // hit inval : switch slot to ZOMBI state
     2031    case ICACHE_CC_INVAL:  // hit inval : switch slot to ZOMBI state
    20332032    {
    20342033        assert (not r_icache_cc_send_req.read() &&
     
    20372036
    20382037#ifdef INSTRUMENTATION
    2039 m_cpt_icache_dir_read++;
     2038        m_cpt_icache_dir_read++;
    20402039#endif
    20412040
    20422041        // Switch slot state to ZOMBI and send CLEANUP command
    2043         r_icache.write_dir( r_icache_cc_way.read(),
    2044                             r_icache_cc_set.read(),
    2045                             CACHE_SLOT_STATE_ZOMBI );
     2042        r_icache.write_dir(r_icache_cc_way.read(),
     2043                           r_icache_cc_set.read(),
     2044                           CACHE_SLOT_STATE_ZOMBI);
    20462045
    20472046        // coherence request completed
     
    20512050        r_icache_cc_send_type  = CC_TYPE_CLEANUP;
    20522051
    2053         r_icache_fsm           = r_icache_fsm_save.read();
     2052        r_icache_fsm = r_icache_fsm_save.read();
    20542053
    20552054#if DEBUG_ICACHE
    2056 if ( m_debug_icache_fsm )
    2057 {
    2058 std::cout << "  <PROC " << name()
    2059           << " ICACHE_CC_INVAL> slot returns to ZOMBI state"
    2060           << " set = " << r_icache_cc_set.read()
    2061           << " / way = " << r_icache_cc_way.read() << std::endl;
    2062 }
     2055        if (m_debug_icache_fsm)
     2056        {
     2057            std::cout << "  <PROC " << name()
     2058                << " ICACHE_CC_INVAL> slot returns to ZOMBI state"
     2059                << " set = " << r_icache_cc_set.read()
     2060                << " / way = " << r_icache_cc_way.read() << std::endl;
     2061        }
    20632062#endif
    20642063
     
    20662065    }
    20672066    ////////////////////
    2068     case ICACHE_CC_UPDT:        // hit update : write one word per cycle
     2067    case ICACHE_CC_UPDT: // hit update : write one word per cycle
    20692068    {
    20702069        assert (not r_icache_cc_send_req.read() &&
     
    20722071                "must not be set");
    20732072
    2074         if ( not r_cc_receive_updt_fifo_be.rok() ) break;
    2075 
    2076 
    2077         size_t  word = r_icache_cc_word.read();
    2078         size_t  way   = r_icache_cc_way.read();
    2079         size_t  set   = r_icache_cc_set.read();
     2073        if (not r_cc_receive_updt_fifo_be.rok()) break;
     2074
     2075
     2076        size_t word = r_icache_cc_word.read();
     2077        size_t way  = r_icache_cc_way.read();
     2078        size_t set  = r_icache_cc_set.read();
    20802079
    20812080        if (r_icache_cc_need_write.read())
    20822081        {
    2083             r_icache.write( way,
    2084                             set,
    2085                             word,
    2086                             r_cc_receive_updt_fifo_data.read(),
    2087                             r_cc_receive_updt_fifo_be.read() );
    2088 
    2089             r_icache_cc_word = word+1;
     2082            r_icache.write(way,
     2083                           set,
     2084                           word,
     2085                           r_cc_receive_updt_fifo_data.read(),
     2086                           r_cc_receive_updt_fifo_be.read());
     2087
     2088            r_icache_cc_word = word + 1;
    20902089
    20912090#ifdef INSTRUMENTATION
    2092 m_cpt_icache_data_write++;
     2091            m_cpt_icache_data_write++;
    20932092#endif
    20942093
    20952094#if DEBUG_ICACHE
    2096 if ( m_debug_icache_fsm )
    2097 {
    2098     std::cout << "  <PROC " << name()
    2099               << " ICACHE_CC_UPDT> Write one word "
    2100               << " set = " << r_icache_cc_set.read()
    2101               << " / way = " << r_icache_cc_way.read()
    2102               << " / word = " << r_icache_cc_word.read() << std::endl;
    2103 }
    2104 #endif
    2105         }
    2106 
    2107         if ( r_cc_receive_updt_fifo_eop.read() )        // last word
     2095            if (m_debug_icache_fsm)
     2096            {
     2097                std::cout << "  <PROC " << name()
     2098                    << " ICACHE_CC_UPDT> Write one word "
     2099                    << " set = " << r_icache_cc_set.read()
     2100                    << " / way = " << r_icache_cc_way.read()
     2101                    << " / word = " << r_icache_cc_word.read() << std::endl;
     2102            }
     2103#endif
     2104        }
     2105
     2106        if (r_cc_receive_updt_fifo_eop.read()) // last word
    21082107        {
    21092108            // no need to write in the cache anymore
    2110             r_icache_cc_need_write        = false;
     2109            r_icache_cc_need_write = false;
    21112110
    21122111            // coherence request completed
    2113             r_cc_receive_icache_req       = false;
     2112            r_cc_receive_icache_req = false;
    21142113
    21152114            // request multicast acknowledgement
     
    21192118            r_icache_cc_send_type         = CC_TYPE_MULTI_ACK;
    21202119
    2121             r_icache_fsm                  = r_icache_fsm_save.read();
     2120            r_icache_fsm = r_icache_fsm_save.read();
    21222121        }
    21232122        //consume fifo if not eop
    2124         cc_receive_updt_fifo_get  = true;
     2123        cc_receive_updt_fifo_get = true;
    21252124
    21262125        break;
     
    22072206    m_drsp.rdata = 0;
    22082207
    2209     switch ( r_dcache_fsm.read() )
     2208    switch (r_dcache_fsm.read())
    22102209    {
    22112210    case DCACHE_IDLE: // There are 10 conditions to exit the IDLE state :
     
    22442243                      // updt_request, wbuf_request, wbuf_write_miss.
    22452244    {
    2246         paddr_t     paddr;
    2247         pte_info_t      tlb_flags;
    2248         size_t          tlb_way;
    2249         size_t          tlb_set;
    2250         paddr_t         tlb_nline = 0;
    2251         size_t          cache_way;
    2252         size_t          cache_set;
    2253         size_t          cache_word;
    2254         uint32_t        cache_rdata = 0;
    2255         bool        tlb_hit = false;
    2256         int             cache_state = CACHE_SLOT_STATE_EMPTY;
    2257 
    2258         bool        tlb_inval_required = false;    // request TLB inval after cache update
    2259         bool        wbuf_write_miss    = false;     // miss a WBUF write request
    2260         bool        updt_request       = false;     // request DCACHE update in P1 stage
    2261         bool        wbuf_request       = false;     // request WBUF write in P1 stage
    2262 
    2263         // physical address computation : systematic DTLB access if activated)
     2245        paddr_t paddr;
     2246        pte_info_t tlb_flags;
     2247        size_t   tlb_way;
     2248        size_t   tlb_set;
     2249        paddr_t  tlb_nline = 0;
     2250        size_t   cache_way;
     2251        size_t   cache_set;
     2252        size_t   cache_word;
     2253        uint32_t cache_rdata = 0;
     2254        bool     tlb_hit = false;
     2255        int      cache_state = CACHE_SLOT_STATE_EMPTY;
     2256
     2257        bool tlb_inval_required = false; // request TLB inval after cache update
     2258        bool wbuf_write_miss = false;    // miss a WBUF write request
     2259        bool updt_request = false;       // request DCACHE update in P1 stage
     2260        bool wbuf_request = false;       // request WBUF write in P1 stage
     2261
     2262        // physical address computation : systematic DTLB access if activated
    22642263        paddr = (paddr_t) m_dreq.addr;
    2265         if ( m_dreq.valid )
    2266         {
    2267             if ( r_mmu_mode.read() & DATA_TLB_MASK )  // DTLB activated
    2268             {
    2269                 tlb_hit = r_dtlb.translate( m_dreq.addr,
    2270                                             &paddr,
    2271                                             &tlb_flags,
    2272                                             &tlb_nline,
    2273                                             &tlb_way,
    2274                                             &tlb_set );
     2264        if (m_dreq.valid)
     2265        {
     2266            if (r_mmu_mode.read() & DATA_TLB_MASK)  // DTLB activated
     2267            {
     2268                tlb_hit = r_dtlb.translate(m_dreq.addr,
     2269                                           &paddr,
     2270                                           &tlb_flags,
     2271                                           &tlb_nline,
     2272                                           &tlb_way,
     2273                                           &tlb_set);
    22752274#ifdef INSTRUMENTATION
    2276 m_cpt_dtlb_read++;
    2277 #endif
    2278             }
    2279             else                                    // identity mapping
     2275                m_cpt_dtlb_read++;
     2276#endif
     2277            }
     2278            else // identity mapping
    22802279            {
    22812280                // we take into account the paddr extension
    22822281                if (vci_param::N > 32)
    2283                     paddr = paddr | ((paddr_t)(r_dcache_paddr_ext.read()) << 32);
     2282                    paddr = paddr | ((paddr_t) (r_dcache_paddr_ext.read()) << 32);
    22842283            }
    22852284        } // end physical address computation
    22862285
    22872286        // systematic DCACHE access depending on r_dcache_updt_req (if activated)
    2288         if ( r_mmu_mode.read() & DATA_CACHE_MASK)
    2289         {
    2290 
    2291             if ( m_dreq.valid and r_dcache_updt_req.read() ) // read DIR and write DATA
    2292             {
    2293                 r_dcache.read_dir( paddr,
    2294                                    &cache_state,
    2295                                    &cache_way,
    2296                                    &cache_set,
    2297                                    &cache_word );
    2298 
    2299                 r_dcache.write( r_dcache_save_cache_way.read(),
    2300                                 r_dcache_save_cache_set.read(),
    2301                                 r_dcache_save_cache_word.read(),
    2302                                 r_dcache_save_wdata.read(),
    2303                                 r_dcache_save_be.read() );
     2287        if (r_mmu_mode.read() & DATA_CACHE_MASK)
     2288        {
     2289
     2290            if (m_dreq.valid and r_dcache_updt_req.read()) // read DIR and write DATA
     2291            {
     2292                r_dcache.read_dir(paddr,
     2293                                  &cache_state,
     2294                                  &cache_way,
     2295                                  &cache_set,
     2296                                  &cache_word);
     2297
     2298                r_dcache.write(r_dcache_save_cache_way.read(),
     2299                               r_dcache_save_cache_set.read(),
     2300                               r_dcache_save_cache_word.read(),
     2301                               r_dcache_save_wdata.read(),
     2302                               r_dcache_save_be.read());
    23042303#ifdef INSTRUMENTATION
    2305 m_cpt_dcache_dir_read++;
    2306 m_cpt_dcache_data_write++;
    2307 #endif
    2308             }
    2309             else if ( m_dreq.valid and not r_dcache_updt_req.read() ) // read DIR and DATA
    2310             {
    2311                 r_dcache.read( paddr,
    2312                                &cache_rdata,
    2313                                &cache_way,
    2314                                &cache_set,
    2315                                &cache_word,
    2316                                &cache_state );
     2304                m_cpt_dcache_dir_read++;
     2305                m_cpt_dcache_data_write++;
     2306#endif
     2307            }
     2308            else if (m_dreq.valid and not r_dcache_updt_req.read()) // read DIR and DATA
     2309            {
     2310                r_dcache.read(paddr,
     2311                              &cache_rdata,
     2312                              &cache_way,
     2313                              &cache_set,
     2314                              &cache_word,
     2315                              &cache_state);
    23172316
    23182317#ifdef INSTRUMENTATION
    2319 m_cpt_dcache_dir_read++;
    2320 m_cpt_dcache_data_read++;
    2321 #endif
    2322             }
    2323             else if ( not m_dreq.valid and r_dcache_updt_req.read() ) // write DATA
    2324             {
    2325                 r_dcache.write( r_dcache_save_cache_way.read(),
    2326                                 r_dcache_save_cache_set.read(),
    2327                                 r_dcache_save_cache_word.read(),
    2328                                 r_dcache_save_wdata.read(),
    2329                                 r_dcache_save_be.read() );
     2318                m_cpt_dcache_dir_read++;
     2319                m_cpt_dcache_data_read++;
     2320#endif
     2321            }
     2322            else if (not m_dreq.valid and r_dcache_updt_req.read()) // write DATA
     2323            {
     2324                r_dcache.write(r_dcache_save_cache_way.read(),
     2325                               r_dcache_save_cache_set.read(),
     2326                               r_dcache_save_cache_word.read(),
     2327                               r_dcache_save_wdata.read(),
     2328                               r_dcache_save_be.read());
    23302329#ifdef INSTRUMENTATION
    2331 m_cpt_dcache_data_write++;
     2330                m_cpt_dcache_data_write++;
    23322331#endif
    23332332            }
     
    23352334
    23362335        // DCACHE update in P1 stage can require ITLB / DTLB inval or flush
    2337         if ( r_dcache_updt_req.read() )
     2336        if (r_dcache_updt_req.read())
    23382337        {
    23392338            size_t way = r_dcache_save_cache_way.read();
    23402339            size_t set = r_dcache_save_cache_set.read();
    23412340
    2342             if ( r_dcache_in_tlb[way*m_dcache_sets+set] )
    2343             {
    2344                 tlb_inval_required       = true;
    2345                     r_dcache_tlb_inval_set   = 0;
    2346                     r_dcache_tlb_inval_line  = r_dcache_save_paddr.read()>>
    2347                                            (uint32_log2(m_dcache_words<<2));
    2348                     r_dcache_in_tlb[way*m_dcache_sets+set] = false;
    2349             }
    2350             else if ( r_dcache_contains_ptd[way*m_dcache_sets+set] )
     2341            if (r_dcache_in_tlb[way * m_dcache_sets + set])
     2342            {
     2343                tlb_inval_required      = true;
     2344                r_dcache_tlb_inval_set  = 0;
     2345                r_dcache_tlb_inval_line = r_dcache_save_paddr.read() >>
     2346                                           (uint32_log2(m_dcache_words << 2));
     2347                r_dcache_in_tlb[way * m_dcache_sets + set] = false;
     2348            }
     2349            else if (r_dcache_contains_ptd[way * m_dcache_sets + set])
    23512350            {
    23522351                r_itlb.reset();
    23532352                r_dtlb.reset();
    2354                     r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     2353                r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    23552354            }
    23562355
    23572356#if DEBUG_DCACHE
    2358 if ( m_debug_dcache_fsm )
    2359 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2360           << " Cache update in P1 stage" << std::dec
    2361           << " / WAY = " << r_dcache_save_cache_way.read()
    2362           << " / SET = " << r_dcache_save_cache_set.read()
    2363           << " / WORD = " << r_dcache_save_cache_word.read() << std::hex
    2364           << " / WDATA = " << r_dcache_save_wdata.read()
    2365           << " / BE = " << r_dcache_save_be.read() << std::endl;
     2357            if (m_debug_dcache_fsm)
     2358                std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2359                    << " Cache update in P1 stage" << std::dec
     2360                    << " / WAY = " << r_dcache_save_cache_way.read()
     2361                    << " / SET = " << r_dcache_save_cache_set.read()
     2362                    << " / WORD = " << r_dcache_save_cache_word.read() << std::hex
     2363                    << " / WDATA = " << r_dcache_save_wdata.read()
     2364                    << " / BE = " << r_dcache_save_be.read() << std::endl;
    23662365#endif
    23672366        } // end test TLB inval
     
    23702369        // Miss if the write request is non cacheable, and there is a pending
    23712370        // non cacheable write, or if the write buffer is full.
    2372         if ( r_dcache_wbuf_req.read() )
    2373         {
    2374             bool wok = r_wbuf.write( r_dcache_save_paddr.read(),
    2375                                      r_dcache_save_be.read(),
    2376                                      r_dcache_save_wdata.read(),
    2377                                      true);
     2371        if (r_dcache_wbuf_req.read())
     2372        {
     2373            bool wok = r_wbuf.write(r_dcache_save_paddr.read(),
     2374                                    r_dcache_save_be.read(),
     2375                                    r_dcache_save_wdata.read(),
     2376                                    true);
    23782377#ifdef INSTRUMENTATION
    2379 m_cpt_wbuf_write++;
    2380 #endif
    2381             if ( not wok ) // miss if write buffer full
     2378            m_cpt_wbuf_write++;
     2379#endif
     2380            if (not wok ) // miss if write buffer full
    23822381            {
    23832382                wbuf_write_miss = true;
     
    23892388
    23902389        // itlb/dtlb invalidation self-request
    2391         if ( tlb_inval_required )
     2390        if (tlb_inval_required)
    23922391        {
    23932392            r_dcache_fsm_scan_save = r_dcache_fsm.read();
     
    23962395
    23972396        // coherence clack request (from DSPIN CLACK)
    2398         else if ( r_dcache_clack_req.read() )
     2397        else if (r_dcache_clack_req.read())
    23992398        {
    24002399            r_dcache_fsm = DCACHE_CC_CHECK;
     
    24022401        }
    24032402        // coherence request (from CC_RECEIVE FSM)
    2404         else if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     2403        else if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    24052404        {
    24062405            r_dcache_fsm = DCACHE_CC_CHECK;
     
    24112410        // we don't take the processor request, and registers
    24122411        // are frozen in case of wbuf_write_miss
    2413         else if ( m_dreq.valid and not wbuf_write_miss )
     2412        else if (m_dreq.valid and not wbuf_write_miss)
    24142413        {
    24152414            // register processor request and DCACHE response
     
    24272426            if (m_dreq.type == iss_t::XTN_READ)
    24282427            {
    2429                 int xtn_opcode = (int)m_dreq.addr/4;
     2428                int xtn_opcode = (int)m_dreq.addr / 4;
    24302429
    24312430                // checking processor mode:
     
    24412440                else
    24422441                {
    2443                     switch( xtn_opcode )
     2442                    switch (xtn_opcode)
    24442443                    {
    24452444                    case iss_t::XTN_INS_ERROR_TYPE:
     
    25162515
    25172516                    default:
    2518                         r_mmu_detr = MMU_READ_UNDEFINED_XTN;
     2517                        r_mmu_detr   = MMU_READ_UNDEFINED_XTN;
    25192518                        r_mmu_dbvar  = m_dreq.addr;
    25202519                        m_drsp.valid = true;
     
    25342533            else if (m_dreq.type == iss_t::XTN_WRITE)
    25352534            {
    2536                 int xtn_opcode      = (int)m_dreq.addr/4;
     2535                int xtn_opcode = (int)m_dreq.addr / 4;
    25372536                r_dcache_xtn_opcode = xtn_opcode;
    25382537
    25392538                // checking processor mode:
    2540                 if ( (m_dreq.mode  == iss_t::MODE_USER) &&
     2539                if ((m_dreq.mode  == iss_t::MODE_USER) &&
    25412540                     (xtn_opcode != iss_t::XTN_SYNC) &&
    25422541                     (xtn_opcode != iss_t::XTN_DCACHE_INVAL) &&
    25432542                     (xtn_opcode != iss_t::XTN_DCACHE_FLUSH) &&
    25442543                     (xtn_opcode != iss_t::XTN_ICACHE_INVAL) &&
    2545                      (xtn_opcode != iss_t::XTN_ICACHE_FLUSH) )
     2544                     (xtn_opcode != iss_t::XTN_ICACHE_FLUSH))
    25462545                {
    25472546                    r_mmu_detr   = MMU_WRITE_PRIVILEGE_VIOLATION;
     
    25542553                else
    25552554                {
    2556                     switch( xtn_opcode )
     2555                    switch (xtn_opcode)
    25572556                    {
    2558                     case iss_t::XTN_PTPR:                       // itlb & dtlb must be flushed
     2557                    case iss_t::XTN_PTPR: // itlb & dtlb must be flushed
    25592558                        r_dcache_xtn_req = true;
    25602559                        r_dcache_fsm     = DCACHE_XTN_SWITCH;
    25612560                        break;
    25622561
    2563                     case iss_t::XTN_TLB_MODE:                   // no cache or tlb access
    2564                         r_mmu_mode       = m_dreq.wdata;
    2565                         m_drsp.valid     = true;
    2566                         r_dcache_fsm     = DCACHE_IDLE;
     2562                    case iss_t::XTN_TLB_MODE: // no cache or tlb access
     2563                        r_mmu_mode   = m_dreq.wdata;
     2564                        m_drsp.valid = true;
     2565                        r_dcache_fsm = DCACHE_IDLE;
    25672566                        break;
    25682567
    2569                     case iss_t::XTN_DTLB_INVAL:                 // dtlb access
    2570                         r_dcache_fsm     = DCACHE_XTN_DT_INVAL;
     2568                    case iss_t::XTN_DTLB_INVAL: // dtlb access
     2569                        r_dcache_fsm = DCACHE_XTN_DT_INVAL;
    25712570                        break;
    25722571
    2573                     case iss_t::XTN_ITLB_INVAL:                 // itlb access
     2572                    case iss_t::XTN_ITLB_INVAL: // itlb access
    25742573                        r_dcache_xtn_req = true;
    25752574                        r_dcache_fsm     = DCACHE_XTN_IT_INVAL;
    25762575                        break;
    25772576
    2578                     case iss_t::XTN_DCACHE_INVAL:               // dcache, dtlb & itlb access
    2579                         r_dcache_fsm     = DCACHE_XTN_DC_INVAL_VA;
     2577                    case iss_t::XTN_DCACHE_INVAL:  // dcache, dtlb & itlb access
     2578                        r_dcache_fsm = DCACHE_XTN_DC_INVAL_VA;
    25802579                        break;
    25812580
    2582                     case iss_t::XTN_MMU_DCACHE_PA_INV:          // dcache, dtlb & itlb access
    2583                         r_dcache_fsm     = DCACHE_XTN_DC_INVAL_PA;
     2581                    case iss_t::XTN_MMU_DCACHE_PA_INV: // dcache, dtlb & itlb access
     2582                        r_dcache_fsm = DCACHE_XTN_DC_INVAL_PA;
    25842583                        if (sizeof(paddr_t) <= 32)
    25852584                        {
     
    25952594                        break;
    25962595
    2597                     case iss_t::XTN_DCACHE_FLUSH:              // itlb and dtlb must be reset
     2596                    case iss_t::XTN_DCACHE_FLUSH: // itlb and dtlb must be reset
    25982597                        r_dcache_flush_count = 0;
    2599                         r_dcache_fsm     = DCACHE_XTN_DC_FLUSH;
     2598                        r_dcache_fsm         = DCACHE_XTN_DC_FLUSH;
    26002599                        break;
    26012600
    2602                     case iss_t::XTN_ICACHE_INVAL:               // icache and itlb access
     2601                    case iss_t::XTN_ICACHE_INVAL: // icache and itlb access
    26032602                        r_dcache_xtn_req = true;
    26042603                        r_dcache_fsm     = DCACHE_XTN_IC_INVAL_VA;
    26052604                        break;
    26062605
    2607                     case iss_t::XTN_MMU_ICACHE_PA_INV:          // icache access
     2606                    case iss_t::XTN_MMU_ICACHE_PA_INV: // icache access
    26082607                        r_dcache_xtn_req = true;
    26092608                        r_dcache_fsm     = DCACHE_XTN_IC_INVAL_PA;
    26102609                        break;
    26112610
    2612                     case iss_t::XTN_ICACHE_FLUSH:               // icache access
     2611                    case iss_t::XTN_ICACHE_FLUSH:   // icache access
    26132612                        r_dcache_xtn_req = true;
    26142613                        r_dcache_fsm     = DCACHE_XTN_IC_FLUSH;
    26152614                        break;
    26162615
    2617                     case iss_t::XTN_SYNC:                       // wait until write buffer empty
    2618                         r_dcache_fsm     = DCACHE_XTN_SYNC;
     2616                    case iss_t::XTN_SYNC:           // wait until write buffer empty
     2617                        r_dcache_fsm = DCACHE_XTN_SYNC;
    26192618                        break;
    26202619
    2621                     case iss_t::XTN_MMU_WORD_LO:                // no cache or tlb access
    2622                         r_mmu_word_lo    = m_dreq.wdata;
    2623                         m_drsp.valid     = true;
    2624                         r_dcache_fsm     = DCACHE_IDLE;
     2620                    case iss_t::XTN_MMU_WORD_LO:    // no cache or tlb access
     2621                        r_mmu_word_lo = m_dreq.wdata;
     2622                        m_drsp.valid  = true;
     2623                        r_dcache_fsm  = DCACHE_IDLE;
    26252624                        break;
    26262625
    2627                     case iss_t::XTN_MMU_WORD_HI:                // no cache or tlb access
    2628                         r_mmu_word_hi    = m_dreq.wdata;
    2629                         m_drsp.valid     = true;
    2630                         r_dcache_fsm     = DCACHE_IDLE;
     2626                    case iss_t::XTN_MMU_WORD_HI:    // no cache or tlb access
     2627                        r_mmu_word_hi = m_dreq.wdata;
     2628                        m_drsp.valid  = true;
     2629                        r_dcache_fsm  = DCACHE_IDLE;
    26312630                        break;
    26322631
    2633                     case iss_t::XTN_MMU_LL_RESET:      // no cache or tlb access
     2632                    case iss_t::XTN_MMU_LL_RESET:   // no cache or tlb access
    26342633                        r_dcache_llsc_valid = false;
    2635                         m_drsp.valid     = true;
    2636                         r_dcache_fsm     = DCACHE_IDLE;
     2634                        m_drsp.valid        = true;
     2635                        r_dcache_fsm        = DCACHE_IDLE;
    26372636                    break;
    26382637
    2639                     case iss_t::XTN_DATA_PADDR_EXT:     // no cache or tlb access
     2638                    case iss_t::XTN_DATA_PADDR_EXT:  // no cache or tlb access
    26402639                        r_dcache_paddr_ext = m_dreq.wdata;
    26412640                        m_drsp.valid       = true;
     
    26432642                    break;
    26442643
    2645                     case iss_t::XTN_INST_PADDR_EXT:     // no cache or tlb access
     2644                    case iss_t::XTN_INST_PADDR_EXT:  // no cache or tlb access
    26462645                        r_dcache_xtn_req = true;
    26472646                        r_dcache_fsm     = DCACHE_XTN_IC_PADDR_EXT;
    26482647                    break;
    26492648
    2650                     case iss_t::XTN_ICACHE_PREFETCH:        // not implemented : no action
    2651                     case iss_t::XTN_DCACHE_PREFETCH:        // not implemented : no action
    2652                         m_drsp.valid     = true;
    2653                         r_dcache_fsm     = DCACHE_IDLE;
     2649                    case iss_t::XTN_ICACHE_PREFETCH: // not implemented : no action
     2650                    case iss_t::XTN_DCACHE_PREFETCH: // not implemented : no action
     2651                        m_drsp.valid = true;
     2652                        r_dcache_fsm = DCACHE_IDLE;
    26542653                    break;
    26552654
     
    26832682            else
    26842683            {
    2685                 bool        valid_req;
    2686                 bool        cacheable;
    2687 
    2688                 if ( not (r_mmu_mode.read() & DATA_TLB_MASK) )          // dtlb not activated
     2684                bool valid_req;
     2685                bool cacheable;
     2686
     2687                if (not (r_mmu_mode.read() & DATA_TLB_MASK)) // dtlb not activated
    26892688                {
    2690                     valid_req     = true;
    2691 
    2692                     if ( not (r_mmu_mode.read() & DATA_CACHE_MASK) ) cacheable = false;
     2689                    valid_req = true;
     2690
     2691                    if (not (r_mmu_mode.read() & DATA_CACHE_MASK)) cacheable = false;
    26932692                    else cacheable = m_cacheability_table[(uint64_t)m_dreq.addr];
    26942693                }
    2695                 else                                                                       // dtlb activated
     2694                else // dtlb activated
    26962695                {
    2697                     if ( tlb_hit )                                      // tlb hit
     2696                    if (tlb_hit) // tlb hit
    26982697                    {
    26992698                        // cacheability
    2700                         if ( not (r_mmu_mode.read() & DATA_CACHE_MASK) ) cacheable = false;
     2699                        if (not (r_mmu_mode.read() & DATA_CACHE_MASK)) cacheable = false;
    27012700                        else cacheable = tlb_flags.c;
    27022701
    27032702                        // access rights checking
    2704                         if ( not tlb_flags.u and (m_dreq.mode == iss_t::MODE_USER))
     2703                        if (not tlb_flags.u and (m_dreq.mode == iss_t::MODE_USER))
    27052704                        {
    2706                             if ( (m_dreq.type == iss_t::DATA_READ) or
    2707                                  (m_dreq.type == iss_t::DATA_LL) )
     2705                            if ((m_dreq.type == iss_t::DATA_READ) or
     2706                                 (m_dreq.type == iss_t::DATA_LL))
    27082707                            {
    27092708                                r_mmu_detr = MMU_READ_PRIVILEGE_VIOLATION;
     
    27192718                            m_drsp.rdata = 0;
    27202719#if DEBUG_DCACHE
    2721 if ( m_debug_dcache_fsm )
    2722 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2723           << " HIT in dtlb, but privilege violation" << std::endl;
     2720                            if (m_debug_dcache_fsm)
     2721                                std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2722                                    << " HIT in dtlb, but privilege violation" << std::endl;
    27242723#endif
    27252724                        }
    2726                         else if ( not tlb_flags.w and
     2725                        else if (not tlb_flags.w and
    27272726                                  ((m_dreq.type == iss_t::DATA_WRITE) or
    2728                                    (m_dreq.type == iss_t::DATA_SC)) )
     2727                                   (m_dreq.type == iss_t::DATA_SC)))
    27292728                        {
    27302729                            r_mmu_detr   = MMU_WRITE_ACCES_VIOLATION;
     
    27352734                            m_drsp.rdata = 0;
    27362735#if DEBUG_DCACHE
    2737 if ( m_debug_dcache_fsm )
    2738 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2739           << " HIT in dtlb, but writable violation" << std::endl;
     2736                            if (m_debug_dcache_fsm)
     2737                                std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2738                                    << " HIT in dtlb, but writable violation" << std::endl;
    27402739#endif
    27412740                        }
    27422741                        else
    27432742                        {
    2744                             valid_req    = true;
     2743                            valid_req = true;
    27452744                        }
    27462745                    }
    2747                     else                                                // tlb miss
     2746                    else // tlb miss
    27482747                    {
    2749                         valid_req            = false;
    2750                         r_dcache_tlb_vaddr   = m_dreq.addr;
    2751                         r_dcache_tlb_ins     = false;
    2752                         r_dcache_fsm         = DCACHE_TLB_MISS;
     2748                        valid_req          = false;
     2749                        r_dcache_tlb_vaddr = m_dreq.addr;
     2750                        r_dcache_tlb_ins   = false;
     2751                        r_dcache_fsm       = DCACHE_TLB_MISS;
    27532752                    }
    27542753                }    // end DTLB activated
    27552754
    2756                 if ( valid_req )        // processor request is valid (after MMU check)
     2755                if (valid_req) // processor request is valid (after MMU check)
    27572756                {
    27582757                    // READ request
     
    27602759                    // We request a VCI transaction to CMD FSM if miss or uncachable
    27612760
    2762                     if ( ((m_dreq.type == iss_t::DATA_READ))
    2763                           and not r_dcache_updt_req.read() )
     2761                    if (((m_dreq.type == iss_t::DATA_READ))
     2762                          and not r_dcache_updt_req.read())
    27642763                    {
    2765                         if ( cacheable )                // cacheable read
     2764                        if (cacheable) // cacheable read
    27662765                        {
    2767                             if ( cache_state == CACHE_SLOT_STATE_EMPTY )   // cache miss
     2766                            if (cache_state == CACHE_SLOT_STATE_EMPTY)   // cache miss
    27682767                            {
    27692768#ifdef INSTRUMENTATION
    2770 m_cpt_dcache_miss++;
     2769                                m_cpt_dcache_miss++;
    27712770#endif
    27722771                                // request a VCI DMISS transaction
     
    27762775                                r_dcache_fsm          = DCACHE_MISS_SELECT;
    27772776#if DEBUG_DCACHE
    2778 if ( m_debug_dcache_fsm )
    2779 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2780           << " READ MISS in dcache"
    2781           << " / PADDR = " << std::hex << paddr << std::endl;
     2777                                if (m_debug_dcache_fsm)
     2778                                    std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2779                                        << " READ MISS in dcache"
     2780                                        << " / PADDR = " << std::hex << paddr << std::endl;
    27822781#endif
    27832782                            }
    2784                             else if (cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
     2783                            else if (cache_state == CACHE_SLOT_STATE_ZOMBI) // pending cleanup
    27852784                            {
    27862785                                // stalled until cleanup is acknowledged
    27872786                                r_dcache_fsm   = DCACHE_IDLE;
    27882787#if DEBUG_DCACHE
    2789 if ( m_debug_dcache_fsm )
    2790 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2791           << " Pending cleanup, stalled until cleanup acknowledge"
    2792           << " / PADDR = " << std::hex << paddr << std::endl;
     2788                                if (m_debug_dcache_fsm)
     2789                                    std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2790                                        << " Pending cleanup, stalled until cleanup acknowledge"
     2791                                        << " / PADDR = " << std::hex << paddr << std::endl;
    27932792#endif
    27942793                            }
     
    27962795                            {
    27972796#ifdef INSTRUMENTATION
    2798 m_cpt_data_read++;
     2797                                m_cpt_data_read++;
    27992798#endif
    28002799                                // returns data to processor
    2801                                 m_drsp.valid   = true;
    2802                                 m_drsp.error   = false;
    2803                                 m_drsp.rdata   = cache_rdata;
     2800                                m_drsp.valid = true;
     2801                                m_drsp.error = false;
     2802                                m_drsp.rdata = cache_rdata;
    28042803#if DEBUG_DCACHE
    2805 if ( m_debug_dcache_fsm )
    2806 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2807           << " READ HIT in dcache"
    2808           << " : PADDR = " << std::hex << paddr
    2809           << " / DATA  = " << std::hex << cache_rdata << std::endl;
     2804                                if (m_debug_dcache_fsm)
     2805                                    std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2806                                        << " READ HIT in dcache"
     2807                                        << " : PADDR = " << std::hex << paddr
     2808                                        << " / DATA  = " << std::hex << cache_rdata << std::endl;
    28102809#endif
    28112810                            }
    28122811                        }
    2813                         else                                    // uncacheable read
     2812                        else // uncacheable read
    28142813                        {
    2815                             r_dcache_vci_paddr      = paddr;
    2816                             r_dcache_vci_unc_be     = m_dreq.be;
    2817                             r_dcache_vci_unc_write  = false;
    2818                             r_dcache_vci_unc_req    = true;
    2819                             r_dcache_fsm            = DCACHE_UNC_WAIT;
     2814                            r_dcache_vci_paddr     = paddr;
     2815                            r_dcache_vci_unc_be    = m_dreq.be;
     2816                            r_dcache_vci_unc_write = false;
     2817                            r_dcache_vci_unc_req   = true;
     2818                            r_dcache_fsm           = DCACHE_UNC_WAIT;
    28202819#if DEBUG_DCACHE
    2821 if ( m_debug_dcache_fsm )
    2822 std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
    2823           << " READ UNCACHEABLE in dcache"
    2824           << " / PADDR = " << std::hex << paddr << std::endl;
     2820                            if (m_debug_dcache_fsm)
     2821                                std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
     2822                                    << " READ UNCACHEABLE in dcache"
     2823                                    << " / PADDR = " << std::hex << paddr << std::endl;
    28252824#endif
    28262825                        }
     
    28532852                    // physical address) are registered in r_dcache_save registers,
    28542853                    // and the write will be done in the P1 pipeline stage.
    2855                     else if ( m_dreq.type == iss_t::DATA_WRITE )
     2854                    else if (m_dreq.type == iss_t::DATA_WRITE)
    28562855                    {
    2857                         if ( (r_mmu_mode.read() & DATA_TLB_MASK )
    2858                               and not tlb_flags.d )             // Dirty bit must be set
     2856                        if ((r_mmu_mode.read() & DATA_TLB_MASK)
     2857                              and not tlb_flags.d) // Dirty bit must be set
    28592858                        {
    28602859                            // The PTE physical address is obtained from the nline value (dtlb),
    28612860                            // and from the virtual address (word index)
    2862                             if ( tlb_flags.b )  // PTE1
     2861                            if (tlb_flags.b ) // PTE1
    28632862                            {
    2864                                 r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
    2865                                                        (paddr_t)((m_dreq.addr>>19) & 0x3c);
     2863                                r_dcache_dirty_paddr = (paddr_t)(tlb_nline * (m_dcache_words << 2)) |
     2864                                                       (paddr_t)((m_dreq.addr >> 19) & 0x3c);
    28662865                            }
    2867                             else                // PTE2
     2866                            else // PTE2
    28682867                            {
    2869                                 r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
    2870                                                        (paddr_t)((m_dreq.addr>>9) & 0x38);
     2868                                r_dcache_dirty_paddr = (paddr_t) (tlb_nline * (m_dcache_words << 2)) |
     2869                                                       (paddr_t) ((m_dreq.addr >> 9) & 0x38);
    28712870                            }
    2872                             r_dcache_fsm      = DCACHE_DIRTY_GET_PTE;
     2871                            r_dcache_fsm = DCACHE_DIRTY_GET_PTE;
    28732872                        }
    2874                         else                                    // Write request accepted
     2873                        else // Write request accepted
    28752874                        {
    28762875#ifdef INSTRUMENTATION
    2877 m_cpt_data_write++;
     2876                            m_cpt_data_write++;
    28782877#endif
    28792878                            // cleaning llsc buffer if address matching
    2880                             if ( paddr == r_dcache_llsc_paddr.read() )
     2879                            if (paddr == r_dcache_llsc_paddr.read())
    28812880                                r_dcache_llsc_valid = false;
    28822881
    28832882                            if (not cacheable)
    28842883                            {                           
    2885                                 r_dcache_vci_paddr      = paddr;
    2886                                 r_dcache_vci_wdata      = m_dreq.wdata;
    2887                                 r_dcache_vci_unc_write  = true;
    2888                                 r_dcache_vci_unc_be     = m_dreq.be;
    2889                                 r_dcache_vci_unc_req    = true;
    2890                                 r_dcache_fsm            = DCACHE_UNC_WAIT;
     2884                                r_dcache_vci_paddr     = paddr;
     2885                                r_dcache_vci_wdata     = m_dreq.wdata;
     2886                                r_dcache_vci_unc_write = true;
     2887                                r_dcache_vci_unc_be    = m_dreq.be;
     2888                                r_dcache_vci_unc_req   = true;
     2889                                r_dcache_fsm           = DCACHE_UNC_WAIT;
    28912890                            }
    28922891                            else
    28932892                            {
    28942893                                // response to processor
    2895                                 m_drsp.valid        = true;
     2894                                m_drsp.valid = true;
    28962895                                // activating P1 stage
    28972896                                wbuf_request = true;
     
    29112910                    // We don't check a possible write hit in dcache, as the cache update
    29122911                    // is done by the coherence transaction induced by the SC...
    2913                     else if ( m_dreq.type == iss_t::DATA_SC )
     2912                    else if (m_dreq.type == iss_t::DATA_SC)
    29142913                    {
    2915                         if ( (r_mmu_mode.read() & DATA_TLB_MASK )
    2916                               and not tlb_flags.d )                     // Dirty bit must be set
     2914                        if ((r_mmu_mode.read() & DATA_TLB_MASK)
     2915                              and not tlb_flags.d) // Dirty bit must be set
    29172916                        {
    29182917                            // The PTE physical address is obtained from the nline value (dtlb),
    29192918                            // and the word index (virtual address)
    2920                             if ( tlb_flags.b )  // PTE1
     2919                            if (tlb_flags.b) // PTE1
    29212920                            {
    2922                                 r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
    2923                                                        (paddr_t)((m_dreq.addr>>19) & 0x3c);
     2921                                r_dcache_dirty_paddr = (paddr_t) (tlb_nline * (m_dcache_words << 2)) |
     2922                                                       (paddr_t) ((m_dreq.addr >> 19) & 0x3c);
    29242923                            }
    2925                             else                        // PTE2
     2924                            else // PTE2
    29262925                            {
    2927                                 r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
    2928                                                        (paddr_t)((m_dreq.addr>>9) & 0x38);
     2926                                r_dcache_dirty_paddr = (paddr_t) (tlb_nline * (m_dcache_words << 2)) |
     2927                                                       (paddr_t) ((m_dreq.addr >> 9) & 0x38);
    29292928                            }
    2930                             r_dcache_fsm           = DCACHE_DIRTY_GET_PTE;
     2929                            r_dcache_fsm = DCACHE_DIRTY_GET_PTE;
    29312930                            m_drsp.valid = false;
    29322931                            m_drsp.error = false;
    29332932                            m_drsp.rdata = 0;
    29342933                        }
    2935                         else                                    // SC request accepted
     2934                        else // SC request accepted
    29362935                        {
    29372936#ifdef INSTRUMENTATION
    2938 m_cpt_data_sc++;
     2937                            m_cpt_data_sc++;
    29392938#endif
    29402939                            // checking local success
    2941                             if( r_dcache_llsc_valid.read() and
    2942                                 (r_dcache_llsc_paddr.read() == paddr) ) // local success
     2940                            if (r_dcache_llsc_valid.read() and
     2941                                (r_dcache_llsc_paddr.read() == paddr)) // local success
    29432942                            {
    29442943                                // request an SC CMD and go to DCACHE_SC_WAIT state
     
    29482947                                r_dcache_fsm         = DCACHE_SC_WAIT;
    29492948                            }
    2950                             else                                          // local fail
     2949                            else // local fail
    29512950                            {
    2952                                     m_drsp.valid = true;
    2953                                     m_drsp.error = false;
    2954                                     m_drsp.rdata = 0x1;
     2951                                m_drsp.valid = true;
     2952                                m_drsp.error = false;
     2953                                m_drsp.rdata = 0x1;
    29552954                            }
    29562955                        }
     
    29612960
    29622961        // itlb miss request
    2963         else if ( r_icache_tlb_miss_req.read() and not wbuf_write_miss )
     2962        else if (r_icache_tlb_miss_req.read() and not wbuf_write_miss )
    29642963        {
    29652964            r_dcache_tlb_ins    = true;
     
    29872986                          // r_mmu_ins_* or r_mmu_data* error reporting registers.
    29882987    {
    2989         uint32_t        ptba = 0;
    2990         bool            bypass;
    2991         paddr_t         pte_paddr;
     2988        uint32_t ptba = 0;
     2989        bool     bypass;
     2990        paddr_t  pte_paddr;
    29922991
    29932992        // evaluate bypass in order to skip first level page table access
    2994         if ( r_dcache_tlb_ins.read() )                          // itlb miss
     2993        if (r_dcache_tlb_ins.read()) // itlb miss
    29952994        {
    29962995            bypass = r_itlb.get_bypass(r_dcache_tlb_vaddr.read(), &ptba);
    29972996        }
    2998         else                                                    // dtlb miss
     2997        else // dtlb miss
    29992998        {
    30002999            bypass = r_dtlb.get_bypass(r_dcache_tlb_vaddr.read(), &ptba);
    30013000        }
    30023001
    3003         if ( not bypass )    // Try to read PTE1/PTD1 in dcache
    3004         {
    3005             pte_paddr = (((paddr_t)r_mmu_ptpr.read()) << (INDEX1_NBITS+2)) |
    3006                         ((((paddr_t)r_dcache_tlb_vaddr.read()) >> PAGE_M_NBITS) << 2);
     3002        if (not bypass) // Try to read PTE1/PTD1 in dcache
     3003        {
     3004            pte_paddr = (((paddr_t) r_mmu_ptpr.read()) << (INDEX1_NBITS + 2)) |
     3005                       ((((paddr_t) r_dcache_tlb_vaddr.read()) >> PAGE_M_NBITS) << 2);
    30073006            r_dcache_tlb_paddr = pte_paddr;
    30083007            r_dcache_fsm       = DCACHE_TLB_PTE1_GET;
    30093008        }
    3010         else                  // Try to read PTE2 in dcache
    3011         {
    3012             pte_paddr = (paddr_t)ptba << PAGE_K_NBITS |
    3013                         (paddr_t)(r_dcache_tlb_vaddr.read()&PTD_ID2_MASK)>>(PAGE_K_NBITS-3);
     3009        else // Try to read PTE2 in dcache
     3010        {
     3011            pte_paddr = (paddr_t) ptba << PAGE_K_NBITS |
     3012                        (paddr_t) (r_dcache_tlb_vaddr.read() & PTD_ID2_MASK) >> (PAGE_K_NBITS - 3);
    30143013            r_dcache_tlb_paddr = pte_paddr;
    30153014            r_dcache_fsm       = DCACHE_TLB_PTE2_GET;
     
    30173016
    30183017#if DEBUG_DCACHE
    3019 if ( m_debug_dcache_fsm )
    3020 {
    3021     if ( r_dcache_tlb_ins.read() )
    3022         std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> ITLB miss";
    3023     else
    3024         std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> DTLB miss";
    3025     std::cout << " / VADDR = " << std::hex << r_dcache_tlb_vaddr.read()
    3026               << " / ptpr  = " << (((paddr_t)r_mmu_ptpr.read()) << (INDEX1_NBITS+2))
    3027               << " / BYPASS = " << bypass
    3028               << " / PTE_ADR = " << pte_paddr << std::endl;
    3029 }
     3018        if (m_debug_dcache_fsm)
     3019        {
     3020            if (r_dcache_tlb_ins.read())
     3021                std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> ITLB miss";
     3022            else
     3023                std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> DTLB miss";
     3024            std::cout << " / VADDR = " << std::hex << r_dcache_tlb_vaddr.read()
     3025                << " / ptpr  = " << (((paddr_t)r_mmu_ptpr.read()) << (INDEX1_NBITS+2))
     3026                << " / BYPASS = " << bypass
     3027                << " / PTE_ADR = " << pte_paddr << std::endl;
     3028        }
    30303029#endif
    30313030
     
    30333032    }
    30343033    /////////////////////////
    3035     case DCACHE_TLB_PTE1_GET:   // try to read a PT1 entry in dcache
     3034    case DCACHE_TLB_PTE1_GET: // try to read a PT1 entry in dcache
    30363035    {
    30373036        // coherence clack request (from DSPIN CLACK)
    3038         if ( r_dcache_clack_req.read() )
     3037        if (r_dcache_clack_req.read())
    30393038        {
    30403039            r_dcache_fsm = DCACHE_CC_CHECK;
     
    30443043
    30453044        // coherence request (from CC_RECEIVE FSM)
    3046         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3045        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    30473046        {
    30483047            r_dcache_fsm = DCACHE_CC_CHECK;
     
    30513050        }
    30523051
    3053         uint32_t        entry;
    3054         size_t          way;
    3055         size_t          set;
    3056         size_t          word;
    3057         int         cache_state;
    3058         r_dcache.read( r_dcache_tlb_paddr.read(),
    3059                        &entry,
    3060                        &way,
    3061                        &set,
    3062                        &word,
    3063                        &cache_state );
     3052        uint32_t entry;
     3053        size_t way;
     3054        size_t set;
     3055        size_t word;
     3056        int    cache_state;
     3057        r_dcache.read(r_dcache_tlb_paddr.read(),
     3058                      &entry,
     3059                      &way,
     3060                      &set,
     3061                      &word,
     3062                      &cache_state);
    30643063#ifdef INSTRUMENTATION
    3065 m_cpt_dcache_data_read++;
    3066 m_cpt_dcache_dir_read++;
    3067 #endif
    3068         if ( cache_state == CACHE_SLOT_STATE_VALID )   // hit in dcache
    3069         {
    3070             if ( not (entry & PTE_V_MASK) )     // unmapped
    3071             {
    3072                 if ( r_dcache_tlb_ins.read() )
     3064        m_cpt_dcache_data_read++;
     3065        m_cpt_dcache_dir_read++;
     3066#endif
     3067        if (cache_state == CACHE_SLOT_STATE_VALID)   // hit in dcache
     3068        {
     3069            if (not (entry & PTE_V_MASK)) // unmapped
     3070            {
     3071                if (r_dcache_tlb_ins.read())
    30733072                {
    30743073                    r_mmu_ietr             = MMU_READ_PT1_UNMAPPED;
     
    30793078                else
    30803079                {
    3081                     r_mmu_detr             = MMU_READ_PT1_UNMAPPED;
    3082                     r_mmu_dbvar            = r_dcache_tlb_vaddr.read();
    3083                     m_drsp.valid             = true;
    3084                     m_drsp.error             = true;
     3080                    r_mmu_detr   = MMU_READ_PT1_UNMAPPED;
     3081                    r_mmu_dbvar  = r_dcache_tlb_vaddr.read();
     3082                    m_drsp.valid = true;
     3083                    m_drsp.error = true;
    30853084                }
    3086                 r_dcache_fsm          = DCACHE_IDLE;
     3085                r_dcache_fsm = DCACHE_IDLE;
    30873086
    30883087#if DEBUG_DCACHE
    3089 if ( m_debug_dcache_fsm )
    3090 {
    3091     std::cout << "  <PROC " << name()
    3092               << " DCACHE_TLB_PTE1_GET> HIT in dcache, but unmapped"
    3093               << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
    3094               << std::dec << " / way = " << way
    3095               << std::dec << " / set = " << set
    3096               << std::dec << " / word = " << word
    3097               << std::hex << " / PTE1 = " << entry << std::endl;
    3098 }
    3099 #endif
    3100 
    3101             }
    3102             else if( entry & PTE_T_MASK )       //  PTD : me must access PT2
     3088                if (m_debug_dcache_fsm)
     3089                {
     3090                    std::cout << "  <PROC " << name()
     3091                        << " DCACHE_TLB_PTE1_GET> HIT in dcache, but unmapped"
     3092                        << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
     3093                        << std::dec << " / way = " << way
     3094                        << std::dec << " / set = " << set
     3095                        << std::dec << " / word = " << word
     3096                        << std::hex << " / PTE1 = " << entry << std::endl;
     3097                }
     3098#endif
     3099
     3100            }
     3101            else if (entry & PTE_T_MASK ) //  PTD : me must access PT2
    31033102            {
    31043103                // mark the cache line ac containing a PTD
    3105                 r_dcache_contains_ptd[m_dcache_sets*way+set] = true;
     3104                r_dcache_contains_ptd[m_dcache_sets * way + set] = true;
    31063105
    31073106                // register bypass
    3108                 if ( r_dcache_tlb_ins.read() )          // itlb
     3107                if (r_dcache_tlb_ins.read()) // itlb
    31093108                {
    31103109                    r_itlb.set_bypass(r_dcache_tlb_vaddr.read(),
    31113110                                      entry & ((1 << (m_paddr_nbits-PAGE_K_NBITS)) - 1),
    3112                                       r_dcache_tlb_paddr.read() / (m_icache_words<<2) );
     3111                                      r_dcache_tlb_paddr.read() / (m_icache_words << 2));
    31133112                }
    3114                 else                                    // dtlb
     3113                else // dtlb
    31153114                {
    31163115                    r_dtlb.set_bypass(r_dcache_tlb_vaddr.read(),
    31173116                                      entry & ((1 << (m_paddr_nbits-PAGE_K_NBITS)) - 1),
    3118                                       r_dcache_tlb_paddr.read() / (m_dcache_words<<2) );
     3117                                      r_dcache_tlb_paddr.read() / (m_dcache_words << 2));
    31193118                }
    31203119                r_dcache_tlb_paddr =
    3121                     (paddr_t)(entry & ((1<<(m_paddr_nbits-PAGE_K_NBITS))-1)) << PAGE_K_NBITS |
     3120                    (paddr_t)(entry & ((1 << (m_paddr_nbits - PAGE_K_NBITS)) - 1)) << PAGE_K_NBITS |
    31223121                    (paddr_t)(((r_dcache_tlb_vaddr.read() & PTD_ID2_MASK) >> PAGE_K_NBITS) << 3);
    3123                 r_dcache_fsm       = DCACHE_TLB_PTE2_GET;
     3122                r_dcache_fsm = DCACHE_TLB_PTE2_GET;
    31243123
    31253124#if DEBUG_DCACHE
    3126 if ( m_debug_dcache_fsm )
    3127 {
    3128     std::cout << "  <PROC " << name()
    3129               << " DCACHE_TLB_PTE1_GET> HIT in dcache"
    3130               << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
    3131               << std::dec << " / way = " << way
    3132               << std::dec << " / set = " << set
    3133               << std::dec << " / word = " << word
    3134               << std::hex << " / PTD = " << entry << std::endl;
    3135 }
    3136 #endif
    3137             }
    3138             else                        //  PTE1 :  we must update the TLB
    3139             {
    3140                 r_dcache_in_tlb[m_icache_sets*way+set] = true;
     3125                if (m_debug_dcache_fsm)
     3126                {
     3127                    std::cout << "  <PROC " << name()
     3128                        << " DCACHE_TLB_PTE1_GET> HIT in dcache"
     3129                        << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
     3130                        << std::dec << " / way = " << way
     3131                        << std::dec << " / set = " << set
     3132                        << std::dec << " / word = " << word
     3133                        << std::hex << " / PTD = " << entry << std::endl;
     3134                }
     3135#endif
     3136            }
     3137            else //  PTE1 :  we must update the TLB
     3138            {
     3139                r_dcache_in_tlb[m_icache_sets * way + set] = true;
    31413140                r_dcache_tlb_pte_flags  = entry;
    31423141                r_dcache_tlb_cache_way  = way;
     
    31463145
    31473146#if DEBUG_DCACHE
    3148 if ( m_debug_dcache_fsm )
    3149 {
    3150     std::cout << "  <PROC " << name()
    3151               << " DCACHE_TLB_PTE1_GET> HIT in dcache"
    3152               << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
    3153               << std::dec << " / way = " << way
    3154               << std::dec << " / set = " << set
    3155               << std::dec << " / word = " << word
    3156               << std::hex << " / PTE1 = " << entry << std::endl;
    3157 }
    3158 #endif
    3159             }
    3160         }
    3161         else if ( cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
     3147                if (m_debug_dcache_fsm)
     3148                {
     3149                    std::cout << "  <PROC " << name()
     3150                        << " DCACHE_TLB_PTE1_GET> HIT in dcache"
     3151                        << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
     3152                        << std::dec << " / way = " << way
     3153                        << std::dec << " / set = " << set
     3154                        << std::dec << " / word = " << word
     3155                        << std::hex << " / PTE1 = " << entry << std::endl;
     3156                }
     3157#endif
     3158            }
     3159        }
     3160        else if (cache_state == CACHE_SLOT_STATE_ZOMBI) // pending cleanup
    31623161        {
    31633162            // stalled until cleanup is acknowledged
    3164             r_dcache_fsm   = DCACHE_TLB_PTE1_GET;
    3165         }
    3166         else            // we must load the missing cache line in dcache
    3167         {
    3168             r_dcache_vci_miss_req  = true;
    3169             r_dcache_vci_paddr     = r_dcache_tlb_paddr.read();
    3170             r_dcache_save_paddr    = r_dcache_tlb_paddr.read();
    3171             r_dcache_miss_type     = PTE1_MISS;
    3172             r_dcache_fsm           = DCACHE_MISS_SELECT;
     3163            r_dcache_fsm = DCACHE_TLB_PTE1_GET;
     3164        }
     3165        else // we must load the missing cache line in dcache
     3166        {
     3167            r_dcache_vci_miss_req = true;
     3168            r_dcache_vci_paddr    = r_dcache_tlb_paddr.read();
     3169            r_dcache_save_paddr   = r_dcache_tlb_paddr.read();
     3170            r_dcache_miss_type    = PTE1_MISS;
     3171            r_dcache_fsm          = DCACHE_MISS_SELECT;
    31733172
    31743173#if DEBUG_DCACHE
    3175 if ( m_debug_dcache_fsm )
    3176 {
    3177     std::cout << "  <PROC " << name()
    3178               << " DCACHE_TLB_PTE1_GET> MISS in dcache:"
    3179               << " PTE1 address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
    3180 }
     3174            if (m_debug_dcache_fsm)
     3175            {
     3176                std::cout << "  <PROC " << name()
     3177                    << " DCACHE_TLB_PTE1_GET> MISS in dcache:"
     3178                    << " PTE1 address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
     3179            }
    31813180#endif
    31823181        }
     
    31843183    }
    31853184    ////////////////////////////
    3186     case DCACHE_TLB_PTE1_SELECT:        // select a slot for PTE1
    3187     {
    3188         size_t  way;
    3189         size_t  set;
    3190 
    3191         if ( r_dcache_tlb_ins.read() )
    3192         {
    3193             r_itlb.select( r_dcache_tlb_vaddr.read(),
    3194                            true,  // PTE1
    3195                            &way,
    3196                            &set );
     3185    case DCACHE_TLB_PTE1_SELECT: // select a slot for PTE1
     3186    {
     3187        size_t way;
     3188        size_t set;
     3189
     3190        if (r_dcache_tlb_ins.read())
     3191        {
     3192            r_itlb.select(r_dcache_tlb_vaddr.read(),
     3193                          true,  // PTE1
     3194                          &way,
     3195                          &set);
    31973196#ifdef INSTRUMENTATION
    3198 m_cpt_itlb_read++;
     3197            m_cpt_itlb_read++;
    31993198#endif
    32003199        }
    32013200        else
    32023201        {
    3203             r_dtlb.select( r_dcache_tlb_vaddr.read(),
    3204                            true,  // PTE1
    3205                            &way,
    3206                            &set );
     3202            r_dtlb.select(r_dcache_tlb_vaddr.read(),
     3203                          true,  // PTE1
     3204                          &way,
     3205                          &set);
    32073206#ifdef INSTRUMENTATION
    3208 m_cpt_dtlb_read++;
     3207            m_cpt_dtlb_read++;
    32093208#endif
    32103209        }
     
    32143213
    32153214#if DEBUG_DCACHE
    3216 if ( m_debug_dcache_fsm )
    3217 {
    3218     if ( r_dcache_tlb_ins.read() )
    3219         std::cout << "  <PROC " << name()
    3220                   << " DCACHE_TLB_PTE1_SELECT> Select a slot in ITLB:";
    3221     else
    3222         std::cout << "  <PROC " << name()
    3223                   << ".DCACHE_TLB_PTE1_SELECT> Select a slot in DTLB:";
    3224         std::cout << " way = " << std::dec << way
    3225                   << " / set = " << set << std::endl;
    3226 }
     3215        if (m_debug_dcache_fsm)
     3216        {
     3217            if (r_dcache_tlb_ins.read())
     3218                std::cout << "  <PROC " << name()
     3219                    << " DCACHE_TLB_PTE1_SELECT> Select a slot in ITLB:";
     3220            else
     3221                std::cout << "  <PROC " << name()
     3222                    << ".DCACHE_TLB_PTE1_SELECT> Select a slot in DTLB:";
     3223            std::cout << " way = " << std::dec << way
     3224                << " / set = " << set << std::endl;
     3225        }
    32273226#endif
    32283227        break;
    32293228    }
    32303229    //////////////////////////
    3231     case DCACHE_TLB_PTE1_UPDT:  // write a new PTE1 in tlb after testing the L/R bit
     3230    case DCACHE_TLB_PTE1_UPDT:  // write a new PTE1 in tlb after testing the L/R bit
    32323231                                // - if L/R bit already set, exit the sub-fsm.
    32333232                                // - if not, we update the page table but we dont write
     
    32353234                                //   the coherence mechanism.
    32363235    {
    3237         paddr_t   nline    = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words)+2);
    3238         uint32_t  pte      = r_dcache_tlb_pte_flags.read();
    3239         bool      pt_updt  = false;
    3240         bool      local    = true;
     3236        paddr_t nline = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words) + 2);
     3237        uint32_t pte  = r_dcache_tlb_pte_flags.read();
     3238        bool pt_updt  = false;
     3239        bool local    = true;
    32413240
    32423241        // We should compute the access locality:
     
    32473246        // As long as this computation is not done, all access are local.
    32483247
    3249         if ( local )                                            // local access
    3250         {
    3251             if ( not ((pte & PTE_L_MASK) == PTE_L_MASK) ) // we must set the L bit
     3248        if (local) // local access
     3249        {
     3250            if (not ((pte & PTE_L_MASK) == PTE_L_MASK)) // we must set the L bit
    32523251            {
    32533252                pt_updt                = true;
    3254                 r_dcache_vci_cas_old    = pte;
    3255                 r_dcache_vci_cas_new    = pte | PTE_L_MASK;
     3253                r_dcache_vci_cas_old   = pte;
     3254                r_dcache_vci_cas_new   = pte | PTE_L_MASK;
    32563255                pte                    = pte | PTE_L_MASK;
    32573256                r_dcache_tlb_pte_flags = pte;
    32583257            }
    32593258        }
    3260         else                                                    // remote access
    3261         {
    3262             if ( not ((pte & PTE_R_MASK) == PTE_R_MASK) ) // we must set the R bit
     3259        else // remote access
     3260        {
     3261            if (not ((pte & PTE_R_MASK) == PTE_R_MASK)) // we must set the R bit
    32633262            {
    32643263                pt_updt                = true;
    3265                 r_dcache_vci_cas_old    = pte;
    3266                 r_dcache_vci_cas_new    = pte | PTE_R_MASK;
     3264                r_dcache_vci_cas_old   = pte;
     3265                r_dcache_vci_cas_new   = pte | PTE_R_MASK;
    32673266                pte                    = pte | PTE_R_MASK;
    32683267                r_dcache_tlb_pte_flags = pte;
     
    32703269        }
    32713270
    3272         if ( not pt_updt )                                      // update TLB and return
    3273         {
    3274             if ( r_dcache_tlb_ins.read() )
    3275             {
    3276                 r_itlb.write( true,             // 2M page
    3277                               pte,
    3278                               0,                // argument unused for a PTE1
    3279                               r_dcache_tlb_vaddr.read(),
    3280                               r_dcache_tlb_way.read(),
    3281                               r_dcache_tlb_set.read(),
    3282                               nline );
     3271        if (not pt_updt) // update TLB and return
     3272        {
     3273            if (r_dcache_tlb_ins.read())
     3274            {
     3275                r_itlb.write(true, // 2M page
     3276                             pte,
     3277                             0, // argument unused for a PTE1
     3278                             r_dcache_tlb_vaddr.read(),
     3279                             r_dcache_tlb_way.read(),
     3280                             r_dcache_tlb_set.read(),
     3281                             nline);
    32833282#ifdef INSTRUMENTATION
    3284 m_cpt_itlb_write++;
     3283                m_cpt_itlb_write++;
    32853284#endif
    32863285
    32873286#if DEBUG_DCACHE
    3288 if ( m_debug_dcache_fsm )
    3289 {
    3290     std::cout << "  <PROC " << name()
    3291               << " DCACHE_TLB_PTE1_UPDT> write PTE1 in ITLB"
    3292               << " / set = " << std::dec << r_dcache_tlb_set.read()
    3293               << " / way = " << r_dcache_tlb_way.read() << std::endl;
    3294     r_itlb.printTrace();
    3295 }
     3287                if (m_debug_dcache_fsm)
     3288                {
     3289                    std::cout << "  <PROC " << name()
     3290                        << " DCACHE_TLB_PTE1_UPDT> write PTE1 in ITLB"
     3291                        << " / set = " << std::dec << r_dcache_tlb_set.read()
     3292                        << " / way = " << r_dcache_tlb_way.read() << std::endl;
     3293                    r_itlb.printTrace();
     3294                }
    32963295#endif
    32973296            }
    32983297            else
    32993298            {
    3300                 r_dtlb.write( true,             // 2M page
    3301                               pte,
    3302                               0,                // argument unused for a PTE1
    3303                               r_dcache_tlb_vaddr.read(),
    3304                               r_dcache_tlb_way.read(),
    3305                               r_dcache_tlb_set.read(),
    3306                               nline );
     3299                r_dtlb.write(true, // 2M page
     3300                             pte,
     3301                             0, // argument unused for a PTE1
     3302                             r_dcache_tlb_vaddr.read(),
     3303                             r_dcache_tlb_way.read(),
     3304                             r_dcache_tlb_set.read(),
     3305                             nline);
    33073306#ifdef INSTRUMENTATION
    3308 m_cpt_dtlb_write++;
     3307                m_cpt_dtlb_write++;
    33093308#endif
    33103309
    33113310#if DEBUG_DCACHE
    3312 if ( m_debug_dcache_fsm )
    3313 {
    3314     std::cout << "  <PROC " << name()
    3315               << " DCACHE_TLB_PTE1_UPDT> write PTE1 in DTLB"
    3316               << " / set = " << std::dec << r_dcache_tlb_set.read()
    3317               << " / way = " << r_dcache_tlb_way.read() << std::endl;
    3318     r_dtlb.printTrace();
    3319 }
     3311                if (m_debug_dcache_fsm)
     3312                {
     3313                    std::cout << "  <PROC " << name()
     3314                        << " DCACHE_TLB_PTE1_UPDT> write PTE1 in DTLB"
     3315                        << " / set = " << std::dec << r_dcache_tlb_set.read()
     3316                        << " / way = " << r_dcache_tlb_way.read() << std::endl;
     3317                    r_dtlb.printTrace();
     3318                }
    33203319#endif
    33213320            }
     
    33273326
    33283327#if DEBUG_DCACHE
    3329 if ( m_debug_dcache_fsm )
    3330 {
    3331     std::cout << "  <PROC " << name()
    3332               << " DCACHE_TLB_PTE1_UPDT> L/R bit update required"
    3333               << std::endl;
    3334 }
     3328            if (m_debug_dcache_fsm)
     3329            {
     3330                std::cout << "  <PROC " << name()
     3331                    << " DCACHE_TLB_PTE1_UPDT> L/R bit update required"
     3332                    << std::endl;
     3333            }
    33353334#endif
    33363335        }
     
    33383337    }
    33393338    /////////////////////////
    3340     case DCACHE_TLB_PTE2_GET:   // Try to get a PTE2 (64 bits) in the dcache
     3339    case DCACHE_TLB_PTE2_GET: // Try to get a PTE2 (64 bits) in the dcache
    33413340    {
    33423341        // coherence clack request (from DSPIN CLACK)
    3343         if ( r_dcache_clack_req.read() )
     3342        if (r_dcache_clack_req.read())
    33443343        {
    33453344            r_dcache_fsm = DCACHE_CC_CHECK;
     
    33493348
    33503349        // coherence request (from CC_RECEIVE FSM)
    3351         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3350        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    33523351        {
    33533352            r_dcache_fsm = DCACHE_CC_CHECK;
     
    33563355        }
    33573356
    3358         uint32_t        pte_flags;
    3359         uint32_t        pte_ppn;
    3360         size_t          way;
    3361         size_t          set;
    3362         size_t          word;
    3363         int         cache_state;
    3364 
    3365         r_dcache.read( r_dcache_tlb_paddr.read(),
    3366                        &pte_flags,
    3367                        &pte_ppn,
    3368                        &way,
    3369                        &set,
    3370                        &word,
    3371                        &cache_state );
     3357        uint32_t pte_flags;
     3358        uint32_t pte_ppn;
     3359        size_t   way;
     3360        size_t   set;
     3361        size_t   word;
     3362        int      cache_state;
     3363
     3364        r_dcache.read(r_dcache_tlb_paddr.read(),
     3365                      &pte_flags,
     3366                      &pte_ppn,
     3367                      &way,
     3368                      &set,
     3369                      &word,
     3370                      &cache_state);
    33723371#ifdef INSTRUMENTATION
    3373 m_cpt_dcache_data_read++;
    3374 m_cpt_dcache_dir_read++;
    3375 #endif
    3376         if ( cache_state == CACHE_SLOT_STATE_VALID )  // hit in dcache
    3377         {
    3378             if ( not (pte_flags & PTE_V_MASK) ) // unmapped
    3379             {
    3380                 if ( r_dcache_tlb_ins.read() )
     3372        m_cpt_dcache_data_read++;
     3373        m_cpt_dcache_dir_read++;
     3374#endif
     3375        if (cache_state == CACHE_SLOT_STATE_VALID) // hit in dcache
     3376        {
     3377            if (not (pte_flags & PTE_V_MASK)) // unmapped
     3378            {
     3379                if (r_dcache_tlb_ins.read())
    33813380                {
    33823381                    r_mmu_ietr             = MMU_READ_PT2_UNMAPPED;
     
    33873386                else
    33883387                {
    3389                     r_mmu_detr             = MMU_READ_PT2_UNMAPPED;
    3390                     r_mmu_dbvar            = r_dcache_tlb_vaddr.read();
    3391                     m_drsp.valid           = true;
    3392                     m_drsp.error           = true;
     3388                    r_mmu_detr   = MMU_READ_PT2_UNMAPPED;
     3389                    r_mmu_dbvar  = r_dcache_tlb_vaddr.read();
     3390                    m_drsp.valid = true;
     3391                    m_drsp.error = true;
    33933392                }
    3394                 r_dcache_fsm               = DCACHE_IDLE;
     3393                r_dcache_fsm = DCACHE_IDLE;
    33953394
    33963395#if DEBUG_DCACHE
    3397 if ( m_debug_dcache_fsm )
    3398 {
    3399     std::cout << "  <PROC " << name()
    3400               << " DCACHE_TLB_PTE2_GET> HIT in dcache, but PTE unmapped"
    3401               << " PTE_FLAGS = " << std::hex << pte_flags
    3402               << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
    3403 }
    3404 #endif
    3405             }
    3406             else                                // mapped : we must update the TLB
    3407             {
    3408                 r_dcache_in_tlb[m_dcache_sets*way+set] = true;
     3396                if (m_debug_dcache_fsm)
     3397                {
     3398                    std::cout << "  <PROC " << name()
     3399                        << " DCACHE_TLB_PTE2_GET> HIT in dcache, but PTE unmapped"
     3400                        << " PTE_FLAGS = " << std::hex << pte_flags
     3401                        << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
     3402                }
     3403#endif
     3404            }
     3405            else // mapped : we must update the TLB
     3406            {
     3407                r_dcache_in_tlb[m_dcache_sets * way + set] = true;
    34093408                r_dcache_tlb_pte_flags  = pte_flags;
    34103409                r_dcache_tlb_pte_ppn    = pte_ppn;
     
    34153414
    34163415#if DEBUG_DCACHE
    3417 if ( m_debug_dcache_fsm )
    3418 {
    3419     std::cout << "  <PROC " << name()
    3420               << " DCACHE_TLB_PTE2_GET> HIT in dcache:"
    3421               << " PTE_FLAGS = " << std::hex << pte_flags
    3422               << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
    3423 }
     3416                if (m_debug_dcache_fsm)
     3417                {
     3418                    std::cout << "  <PROC " << name()
     3419                        << " DCACHE_TLB_PTE2_GET> HIT in dcache:"
     3420                        << " PTE_FLAGS = " << std::hex << pte_flags
     3421                        << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
     3422                }
    34243423#endif
    34253424             }
    34263425        }
    3427         else if ( cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
     3426        else if (cache_state == CACHE_SLOT_STATE_ZOMBI) // pending cleanup
    34283427        {
    34293428            // stalled until cleanup is acknowledged
     
    34313430
    34323431#if DEBUG_DCACHE
    3433 if ( m_debug_dcache_fsm )
    3434 {
    3435     std::cout << "  <PROC " << name()
    3436               << " DCACHE_TLB_PTE2_GET> ZOMBI in dcache: waiting cleanup ack"
    3437               << std::endl;
    3438 }
     3432            if (m_debug_dcache_fsm)
     3433            {
     3434                std::cout << "  <PROC " << name()
     3435                    << " DCACHE_TLB_PTE2_GET> ZOMBI in dcache: waiting cleanup ack"
     3436                    << std::endl;
     3437            }
    34393438#endif
    34403439        }
     
    34483447
    34493448#if DEBUG_DCACHE
    3450 if ( m_debug_dcache_fsm )
    3451 {
    3452     std::cout << "  <PROC " << name()
    3453               << " DCACHE_TLB_PTE2_GET> MISS in dcache:"
    3454               << " PTE address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
    3455 }
     3449            if (m_debug_dcache_fsm)
     3450            {
     3451                std::cout << "  <PROC " << name()
     3452                    << " DCACHE_TLB_PTE2_GET> MISS in dcache:"
     3453                    << " PTE address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
     3454            }
    34563455#endif
    34573456        }
     
    34643463        size_t set;
    34653464
    3466         if ( r_dcache_tlb_ins.read() )
    3467         {
    3468             r_itlb.select( r_dcache_tlb_vaddr.read(),
    3469                            false,       // PTE2
    3470                            &way,
    3471                            &set );
     3465        if (r_dcache_tlb_ins.read())
     3466        {
     3467            r_itlb.select(r_dcache_tlb_vaddr.read(),
     3468                          false, // PTE2
     3469                          &way,
     3470                          &set);
    34723471#ifdef INSTRUMENTATION
    3473 m_cpt_itlb_read++;
     3472            m_cpt_itlb_read++;
    34743473#endif
    34753474        }
    34763475        else
    34773476        {
    3478             r_dtlb.select( r_dcache_tlb_vaddr.read(),
    3479                            false,       // PTE2
    3480                            &way,
    3481                            &set );
     3477            r_dtlb.select(r_dcache_tlb_vaddr.read(),
     3478                          false, // PTE2
     3479                          &way,
     3480                          &set);
    34823481#ifdef INSTRUMENTATION
    3483 m_cpt_dtlb_read++;
     3482            m_cpt_dtlb_read++;
    34843483#endif
    34853484        }
    34863485
    34873486#if DEBUG_DCACHE
    3488 if ( m_debug_dcache_fsm )
    3489 {
    3490     if ( r_dcache_tlb_ins.read() )
    3491         std::cout << "  <PROC " << name()
    3492                   << " DCACHE_TLB_PTE2_SELECT> Select a slot in ITLB:";
    3493     else
    3494         std::cout << "  <PROC " << name()
    3495                   << " DCACHE_TLB_PTE2_SELECT> Select a slot in DTLB:";
    3496         std::cout << " way = " << std::dec << way
    3497                   << " / set = " << set << std::endl;
    3498 }
     3487        if (m_debug_dcache_fsm)
     3488        {
     3489            if (r_dcache_tlb_ins.read())
     3490                std::cout << "  <PROC " << name()
     3491                    << " DCACHE_TLB_PTE2_SELECT> Select a slot in ITLB:";
     3492            else
     3493                std::cout << "  <PROC " << name()
     3494                    << " DCACHE_TLB_PTE2_SELECT> Select a slot in DTLB:";
     3495            std::cout << " way = " << std::dec << way
     3496                << " / set = " << set << std::endl;
     3497        }
    34993498#endif
    35003499        r_dcache_tlb_way = way;
     
    35043503    }
    35053504    //////////////////////////
    3506     case DCACHE_TLB_PTE2_UPDT:  // write a new PTE2 in tlb after testing the L/R bit
     3505    case DCACHE_TLB_PTE2_UPDT:  // write a new PTE2 in tlb after testing the L/R bit
    35073506                                // - if L/R bit already set, exit the sub-fsm.
    35083507                                // - if not, we update the page table but we dont write
     
    35103509                                //   the coherence mechanism.
    35113510    {
    3512         paddr_t         nline     = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words)+2);
    3513         uint32_t        pte_flags = r_dcache_tlb_pte_flags.read();
    3514         uint32_t        pte_ppn   = r_dcache_tlb_pte_ppn.read();
    3515         bool            pt_updt   = false;
    3516         bool            local     = true;
     3511        paddr_t  nline     = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words) + 2);
     3512        uint32_t pte_flags = r_dcache_tlb_pte_flags.read();
     3513        uint32_t pte_ppn   = r_dcache_tlb_pte_ppn.read();
     3514        bool     pt_updt   = false;
     3515        bool     local     = true;
    35173516
    35183517        // We should compute the access locality:
     
    35233522        // As long as this computation is not done, all access are local.
    35243523
    3525         if ( local )                                            // local access
    3526         {
    3527             if ( not ((pte_flags & PTE_L_MASK) == PTE_L_MASK) ) // we must set the L bit
     3524        if (local) // local access
     3525        {
     3526            if (not ((pte_flags & PTE_L_MASK) == PTE_L_MASK)) // we must set the L bit
    35283527            {
    35293528                pt_updt                = true;
     
    35313530                r_dcache_vci_cas_new   = pte_flags | PTE_L_MASK;
    35323531                pte_flags              = pte_flags | PTE_L_MASK;
    3533                         r_dcache_tlb_pte_flags = pte_flags;
     3532                r_dcache_tlb_pte_flags = pte_flags;
    35343533            }
    35353534        }
    35363535        else                                                    // remote access
    35373536        {
    3538             if ( not ((pte_flags & PTE_R_MASK) == PTE_R_MASK) ) // we must set the R bit
     3537            if (not ((pte_flags & PTE_R_MASK) == PTE_R_MASK)) // we must set the R bit
    35393538            {
    35403539                pt_updt                = true;
     
    35423541                r_dcache_vci_cas_new   = pte_flags | PTE_R_MASK;
    35433542                pte_flags              = pte_flags | PTE_R_MASK;
    3544                         r_dcache_tlb_pte_flags = pte_flags;
    3545             }
    3546         }
    3547 
    3548         if ( not pt_updt )                      // update TLB
    3549         {
    3550             if ( r_dcache_tlb_ins.read() )
    3551             {
    3552                 r_itlb.write( false,    // 4K page
     3543                r_dcache_tlb_pte_flags = pte_flags;
     3544            }
     3545        }
     3546
     3547        if (not pt_updt) // update TLB
     3548        {
     3549            if (r_dcache_tlb_ins.read())
     3550            {
     3551                r_itlb.write( false, // 4K page
    35533552                              pte_flags,
    35543553                              pte_ppn,
     
    35583557                              nline );
    35593558#ifdef INSTRUMENTATION
    3560 m_cpt_itlb_write++;
     3559                m_cpt_itlb_write++;
    35613560#endif
    35623561
    35633562#if DEBUG_DCACHE
    3564 if ( m_debug_dcache_fsm )
    3565 {
    3566     std::cout << "  <PROC " << name()
    3567               << " DCACHE_TLB_PTE2_UPDT> write PTE2 in ITLB"
    3568               << " / set = " << std::dec << r_dcache_tlb_set.read()
    3569               << " / way = " << r_dcache_tlb_way.read() << std::endl;
    3570     r_itlb.printTrace();
    3571 }
     3563                if (m_debug_dcache_fsm)
     3564                {
     3565                    std::cout << "  <PROC " << name()
     3566                        << " DCACHE_TLB_PTE2_UPDT> write PTE2 in ITLB"
     3567                        << " / set = " << std::dec << r_dcache_tlb_set.read()
     3568                        << " / way = " << r_dcache_tlb_way.read() << std::endl;
     3569                    r_itlb.printTrace();
     3570                }
    35723571#endif
    35733572            }
    35743573            else
    35753574            {
    3576                 r_dtlb.write( false,    // 4K page
    3577                               pte_flags,
    3578                               pte_ppn,
    3579                               r_dcache_tlb_vaddr.read(),
    3580                               r_dcache_tlb_way.read(),
    3581                               r_dcache_tlb_set.read(),
    3582                               nline );
     3575                r_dtlb.write(false, // 4K page
     3576                             pte_flags,
     3577                             pte_ppn,
     3578                             r_dcache_tlb_vaddr.read(),
     3579                             r_dcache_tlb_way.read(),
     3580                             r_dcache_tlb_set.read(),
     3581                             nline);
    35833582#ifdef INSTRUMENTATION
    3584 m_cpt_dtlb_write++;
     3583                m_cpt_dtlb_write++;
    35853584#endif
    35863585
    35873586#if DEBUG_DCACHE
    3588 if ( m_debug_dcache_fsm )
    3589 {
    3590     std::cout << "  <PROC " << name()
    3591               << " DCACHE_TLB_PTE2_UPDT> write PTE2 in DTLB"
    3592               << " / set = " << std::dec << r_dcache_tlb_set.read()
    3593               << " / way = " << r_dcache_tlb_way.read() << std::endl;
    3594     r_dtlb.printTrace();
    3595 }
     3587                if (m_debug_dcache_fsm)
     3588                {
     3589                    std::cout << "  <PROC " << name()
     3590                        << " DCACHE_TLB_PTE2_UPDT> write PTE2 in DTLB"
     3591                        << " / set = " << std::dec << r_dcache_tlb_set.read()
     3592                        << " / way = " << r_dcache_tlb_way.read() << std::endl;
     3593                    r_dtlb.printTrace();
     3594                }
    35963595#endif
    35973596
     
    36013600        else                                   // update page table but not TLB
    36023601        {
    3603             r_dcache_fsm = DCACHE_TLB_LR_UPDT;  // dcache and page table update
     3602            r_dcache_fsm = DCACHE_TLB_LR_UPDT; // dcache and page table update
    36043603
    36053604#if DEBUG_DCACHE
    3606 if ( m_debug_dcache_fsm )
    3607 {
    3608     std::cout << "  <PROC " << name()
    3609               << " DCACHE_TLB_PTE2_UPDT> L/R bit update required" << std::endl;
    3610 }
     3605            if (m_debug_dcache_fsm)
     3606            {
     3607                std::cout << "  <PROC " << name()
     3608                    << " DCACHE_TLB_PTE2_UPDT> L/R bit update required" << std::endl;
     3609            }
    36113610#endif
    36123611        }
     
    36173616    {
    36183617#if DEBUG_DCACHE
    3619 if ( m_debug_dcache_fsm )
    3620 {
    3621     std::cout << "  <PROC " << name()
    3622               << " DCACHE_TLB_LR_UPDT> Update dcache: (L/R) bit" << std::endl;
    3623 }
     3618        if (m_debug_dcache_fsm)
     3619        {
     3620            std::cout << "  <PROC " << name()
     3621                << " DCACHE_TLB_LR_UPDT> Update dcache: (L/R) bit" << std::endl;
     3622        }
    36243623#endif
    36253624        // r_dcache_vci_cas_old & r_dcache_vci_cas_new registers are already set
     
    36273626
    36283627        // checking llsc reservation buffer
    3629         if ( r_dcache_llsc_paddr.read() == r_dcache_tlb_paddr.read() )
     3628        if (r_dcache_llsc_paddr.read() == r_dcache_tlb_paddr.read())
    36303629            r_dcache_llsc_valid = false;
    36313630
    36323631        // request a CAS CMD and go to DCACHE_TLB_LR_WAIT state
    36333632        r_dcache_vci_cas_req = true;
    3634         r_dcache_fsm         = DCACHE_TLB_LR_WAIT;
     3633        r_dcache_fsm = DCACHE_TLB_LR_WAIT;
    36353634        break;
    36363635    }
    36373636    ////////////////////////
    3638     case DCACHE_TLB_LR_WAIT:            // Waiting the response to SC transaction for DIRTY bit.
     3637    case DCACHE_TLB_LR_WAIT:        // Waiting the response to SC transaction for DIRTY bit.
    36393638                                    // We consume the response in rsp FIFO,
    36403639                                    // and exit the sub-fsm, but we don't
     
    36463645    {
    36473646        // coherence clack request (from DSPIN CLACK)
    3648         if ( r_dcache_clack_req.read() )
     3647        if (r_dcache_clack_req.read())
    36493648        {
    36503649            r_dcache_fsm = DCACHE_CC_CHECK;
     
    36543653
    36553654        // coherence request (from CC_RECEIVE FSM)
    3656         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3655        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    36573656        {
    36583657            r_dcache_fsm = DCACHE_CC_CHECK;
     
    36613660        }
    36623661
    3663         if ( r_vci_rsp_data_error.read() )      // bus error
     3662        if (r_vci_rsp_data_error.read()) // bus error
    36643663        {
    36653664            std::cout << "BUS ERROR in DCACHE_TLB_LR_WAIT state" << std::endl;
     
    36673666            exit(0);
    36683667        }
    3669         else if ( r_vci_rsp_fifo_dcache.rok() ) // response available
     3668        else if (r_vci_rsp_fifo_dcache.rok()) // response available
    36703669        {
    36713670#if DEBUG_DCACHE
    3672 if ( m_debug_dcache_fsm )
    3673 {
    3674     std::cout << "  <PROC " << name()
    3675               << " DCACHE_TLB_LR_WAIT> SC response received" << std::endl;
    3676 }
     3671            if (m_debug_dcache_fsm)
     3672            {
     3673                std::cout << "  <PROC " << name()
     3674                    << " DCACHE_TLB_LR_WAIT> SC response received" << std::endl;
     3675            }
    36773676#endif
    36783677            vci_rsp_fifo_dcache_get = true;
    3679             r_dcache_fsm            = DCACHE_TLB_RETURN;
     3678            r_dcache_fsm = DCACHE_TLB_RETURN;
    36803679        }
    36813680        break;
    36823681    }
    36833682    ///////////////////////
    3684     case DCACHE_TLB_RETURN:             // return to caller depending on tlb miss type
     3683    case DCACHE_TLB_RETURN:  // return to caller depending on tlb miss type
    36853684    {
    36863685#if DEBUG_DCACHE
    3687 if ( m_debug_dcache_fsm )
    3688 {
    3689     std::cout << "  <PROC " << name()
    3690               << " DCACHE_TLB_RETURN> TLB MISS completed" << std::endl;
    3691 }
    3692 #endif
    3693         if ( r_dcache_tlb_ins.read() ) r_icache_tlb_miss_req = false;
     3686        if (m_debug_dcache_fsm)
     3687        {
     3688            std::cout << "  <PROC " << name()
     3689                << " DCACHE_TLB_RETURN> TLB MISS completed" << std::endl;
     3690        }
     3691#endif
     3692        if (r_dcache_tlb_ins.read()) r_icache_tlb_miss_req = false;
    36943693        r_dcache_fsm = DCACHE_IDLE;
    36953694        break;
    36963695    }
    36973696    ///////////////////////
    3698     case DCACHE_XTN_SWITCH:             // The r_ptpr registers must be written,
     3697    case DCACHE_XTN_SWITCH:     // The r_ptpr registers must be written,
    36993698                                // and both itlb and dtlb must be flushed.
    37003699                                // Caution : the itlb miss requests must be taken
     
    37043703    {
    37053704        // coherence clack request (from DSPIN CLACK)
    3706         if ( r_dcache_clack_req.read() )
     3705        if (r_dcache_clack_req.read())
    37073706        {
    37083707            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37123711
    37133712        // coherence request (from CC_RECEIVE FSM)
    3714         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3713        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    37153714        {
    37163715            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37203719
    37213720        // itlb miss request
    3722         if ( r_icache_tlb_miss_req.read() )
    3723         {
    3724             r_dcache_tlb_ins    = true;
    3725             r_dcache_tlb_vaddr  = r_icache_vaddr_save.read();
    3726             r_dcache_fsm        = DCACHE_TLB_MISS;
    3727             break;
    3728         }
    3729 
    3730         if ( not r_dcache_xtn_req.read() )
     3721        if (r_icache_tlb_miss_req.read())
     3722        {
     3723            r_dcache_tlb_ins   = true;
     3724            r_dcache_tlb_vaddr = r_icache_vaddr_save.read();
     3725            r_dcache_fsm       = DCACHE_TLB_MISS;
     3726            break;
     3727        }
     3728
     3729        if (not r_dcache_xtn_req.read())
    37313730        {
    37323731            r_dtlb.flush();
     
    37383737    }
    37393738    /////////////////////
    3740     case DCACHE_XTN_SYNC:               // waiting until write buffer empty
    3741                                 // The coherence request must be taken
    3742                                 // as there is a risk of dead-lock
     3739    case DCACHE_XTN_SYNC:  // waiting until write buffer empty
     3740                           // The coherence request must be taken
     3741                           // as there is a risk of dead-lock
    37433742    {
    37443743        // coherence clack request (from DSPIN CLACK)
    3745         if ( r_dcache_clack_req.read() )
     3744        if (r_dcache_clack_req.read())
    37463745        {
    37473746            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37513750
    37523751        // coherence request (from CC_RECEIVE FSM)
    3753         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3752        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    37543753        {
    37553754            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37583757        }
    37593758
    3760         if ( r_wbuf.empty() )
    3761         {
    3762             m_drsp.valid   = true;
     3759        if (r_wbuf.empty())
     3760        {
     3761            m_drsp.valid = true;
    37633762            r_dcache_fsm = DCACHE_IDLE;
    37643763        }
     
    37743773    {
    37753774        // coherence clack request (from DSPIN CLACK)
    3776         if ( r_dcache_clack_req.read() )
     3775        if (r_dcache_clack_req.read())
    37773776        {
    37783777            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37823781
    37833782        // coherence request (from CC_RECEIVE FSM)
    3784         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3783        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    37853784        {
    37863785            r_dcache_fsm = DCACHE_CC_CHECK;
     
    37903789
    37913790        // itlb miss request
    3792         if ( r_icache_tlb_miss_req.read() )
    3793         {
    3794             r_dcache_tlb_ins    = true;
    3795             r_dcache_tlb_vaddr  = r_icache_vaddr_save.read();
    3796             r_dcache_fsm        = DCACHE_TLB_MISS;
     3791        if (r_icache_tlb_miss_req.read())
     3792        {
     3793            r_dcache_tlb_ins   = true;
     3794            r_dcache_tlb_vaddr = r_icache_vaddr_save.read();
     3795            r_dcache_fsm       = DCACHE_TLB_MISS;
    37973796            break;
    37983797        }
    37993798
    38003799        // test if XTN request to icache completed
    3801         if ( not r_dcache_xtn_req.read() )
     3800        if (not r_dcache_xtn_req.read())
    38023801        {
    38033802            r_dcache_fsm = DCACHE_IDLE;
     
    38073806    }
    38083807    /////////////////////////
    3809     case DCACHE_XTN_DC_FLUSH:   // Invalidate sequencially all cache lines, using
     3808    case DCACHE_XTN_DC_FLUSH:   // Invalidate sequencially all cache lines, using
    38103809                                // r_dcache_flush_count as a slot counter,
    38113810                                // looping in this state until all slots have been visited.
     
    38173816    {
    38183817        // coherence clack request (from DSPIN CLACK)
    3819         if ( r_dcache_clack_req.read() )
     3818        if (r_dcache_clack_req.read())
    38203819        {
    38213820            r_dcache_fsm = DCACHE_CC_CHECK;
     
    38253824
    38263825        // coherence request (from CC_RECEIVE FSM)
    3827         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     3826        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    38283827        {
    38293828            r_dcache_fsm = DCACHE_CC_CHECK;
     
    38323831        }
    38333832
    3834         if ( not r_dcache_cc_send_req.read() ) // blocked until previous cc_send request is sent
    3835         {
    3836             int       state;
    3837             paddr_t   tag;
    3838             size_t    way = r_dcache_flush_count.read()/m_dcache_sets;
    3839             size_t    set = r_dcache_flush_count.read()%m_dcache_sets;
     3833        if (not r_dcache_cc_send_req.read()) // blocked until previous cc_send request is sent
     3834        {
     3835            int     state;
     3836            paddr_t tag;
     3837            size_t  way = r_dcache_flush_count.read()/m_dcache_sets;
     3838            size_t  set = r_dcache_flush_count.read()%m_dcache_sets;
    38403839
    38413840#ifdef INSTRUMENTATION
    3842 m_cpt_dcache_dir_read++;
    3843 #endif
    3844             r_dcache.read_dir( way,
    3845                                set,
    3846                                &tag,
    3847                                &state );
    3848 
    3849             if ( state == CACHE_SLOT_STATE_VALID )        // inval required
     3841            m_cpt_dcache_dir_read++;
     3842#endif
     3843            r_dcache.read_dir(way,
     3844                              set,
     3845                              &tag,
     3846                              &state);
     3847
     3848            if (state == CACHE_SLOT_STATE_VALID) // inval required
    38503849            {
    38513850                // request cleanup
     
    38563855
    38573856                // goes to DCACHE_XTN_DC_FLUSH_GO to inval directory
    3858                 r_dcache_miss_way     = way;
    3859                 r_dcache_miss_set     = set;
    3860                 r_dcache_fsm          = DCACHE_XTN_DC_FLUSH_GO;
    3861             }
    3862             else if ( r_dcache_flush_count.read() ==
    3863                       (m_dcache_sets*m_dcache_ways - 1) )  // last slot
     3857                r_dcache_miss_way = way;
     3858                r_dcache_miss_set = set;
     3859                r_dcache_fsm      = DCACHE_XTN_DC_FLUSH_GO;
     3860            }
     3861            else if (r_dcache_flush_count.read() ==
     3862                      (m_dcache_sets*m_dcache_ways - 1))  // last slot
    38643863            {
    38653864                r_dtlb.reset();
     
    38703869
    38713870            // saturation counter
    3872             if ( r_dcache_flush_count.read() < (m_dcache_sets*m_dcache_ways - 1) )
     3871            if (r_dcache_flush_count.read() < (m_dcache_sets * m_dcache_ways - 1))
    38733872                r_dcache_flush_count = r_dcache_flush_count.read() + 1;
    38743873        }
     
    38833882        size_t set = r_dcache_miss_set.read();
    38843883
    3885         r_dcache_in_tlb[m_dcache_sets*way+set]       = false;
    3886         r_dcache_contains_ptd[m_dcache_sets*way+set] = false;
     3884        r_dcache_in_tlb[m_dcache_sets * way + set]       = false;
     3885        r_dcache_contains_ptd[m_dcache_sets * way + set] = false;
    38873886
    38883887#ifdef INSTRUMENTATION
    3889 m_cpt_dcache_dir_write++;
    3890 #endif
    3891         r_dcache.write_dir( way,
    3892                             set,
    3893                             CACHE_SLOT_STATE_ZOMBI );
    3894 
    3895         if ( r_dcache_flush_count.read() ==
    3896              (m_dcache_sets*m_dcache_ways - 1) )  // last slot
     3888        m_cpt_dcache_dir_write++;
     3889#endif
     3890        r_dcache.write_dir(way,
     3891                           set,
     3892                           CACHE_SLOT_STATE_ZOMBI);
     3893
     3894        if (r_dcache_flush_count.read() ==
     3895             (m_dcache_sets*m_dcache_ways - 1))  // last slot
    38973896        {
    38983897            r_dtlb.reset();
     
    39083907    }
    39093908    /////////////////////////
    3910     case DCACHE_XTN_DT_INVAL:   // handling processor XTN_DTLB_INVAL request
     3909    case DCACHE_XTN_DT_INVAL: // handling processor XTN_DTLB_INVAL request
    39113910    {
    39123911        r_dtlb.inval(r_dcache_save_wdata.read());
    3913         r_dcache_fsm        = DCACHE_IDLE;
    3914         m_drsp.valid          = true;
     3912        r_dcache_fsm = DCACHE_IDLE;
     3913        m_drsp.valid = true;
    39153914        break;
    39163915    }
     
    39183917    case DCACHE_XTN_DC_INVAL_VA:  // selective cache line invalidate with virtual address
    39193918                                  // requires 3 cycles: access tlb, read cache, inval cache
    3920                                   // we compute the physical address in this state
     3919                                  // we compute the physical address in this state
    39213920    {
    39223921        paddr_t paddr;
    3923         bool    hit;
    3924 
    3925         if ( r_mmu_mode.read() & DATA_TLB_MASK )        // dtlb activated
     3922        bool hit;
     3923
     3924        if (r_mmu_mode.read() & DATA_TLB_MASK) // dtlb activated
    39263925        {
    39273926
    39283927#ifdef INSTRUMENTATION
    3929 m_cpt_dtlb_read++;
    3930 #endif
    3931             hit = r_dtlb.translate( r_dcache_save_wdata.read(),
    3932                                     &paddr );
    3933         }
    3934         else                                            // dtlb not activated
     3928            m_cpt_dtlb_read++;
     3929#endif
     3930            hit = r_dtlb.translate(r_dcache_save_wdata.read(),
     3931                                   &paddr);
     3932        }
     3933        else // dtlb not activated
    39353934        {
    39363935            paddr = (paddr_t)r_dcache_save_wdata.read();
    39373936            if (vci_param::N > 32)
    39383937                paddr = paddr | ((paddr_t)(r_dcache_paddr_ext.read()) << 32);
    3939             hit   = true;
    3940         }
    3941 
    3942         if ( hit )              // tlb hit
     3938            hit = true;
     3939        }
     3940
     3941        if (hit) // tlb hit
    39433942        {
    39443943            r_dcache_save_paddr = paddr;
    3945             r_dcache_fsm      = DCACHE_XTN_DC_INVAL_PA;
    3946         }
    3947         else                    // tlb miss
    3948         {
     3944            r_dcache_fsm = DCACHE_XTN_DC_INVAL_PA;
     3945        }
     3946        else // tlb miss
     3947        {
    39493948
    39503949#ifdef INSTRUMENTATION
    3951 m_cpt_dtlb_miss++;
    3952 #endif
    3953             r_dcache_tlb_ins    = false;                // dtlb
    3954             r_dcache_tlb_vaddr  = r_dcache_save_wdata.read();
    3955             r_dcache_fsm        = DCACHE_TLB_MISS;
     3950            m_cpt_dtlb_miss++;
     3951#endif
     3952            r_dcache_tlb_ins   = false; // dtlb
     3953            r_dcache_tlb_vaddr = r_dcache_save_wdata.read();
     3954            r_dcache_fsm       = DCACHE_TLB_MISS;
    39563955        }
    39573956
    39583957#if DEBUG_DCACHE
    3959 if ( m_debug_dcache_fsm )
    3960 {
    3961     std::cout << "  <PROC " << name()
    3962               << " DCACHE_XTN_DC_INVAL_VA> Compute physical address" << std::hex
    3963               << " / VADDR = " << r_dcache_save_wdata.read()
    3964               << " / PADDR = " << paddr << std::endl;
    3965 }
     3958        if (m_debug_dcache_fsm)
     3959        {
     3960            std::cout << "  <PROC " << name()
     3961                << " DCACHE_XTN_DC_INVAL_VA> Compute physical address" << std::hex
     3962                << " / VADDR = " << r_dcache_save_wdata.read()
     3963                << " / PADDR = " << paddr << std::endl;
     3964        }
    39663965#endif
    39673966
     
    39733972                                  // In this state we read dcache.
    39743973    {
    3975         size_t          way;
    3976         size_t          set;
    3977         size_t          word;
    3978         int         state;
     3974        size_t way;
     3975        size_t set;
     3976        size_t word;
     3977        int    state;
    39793978
    39803979#ifdef INSTRUMENTATION
    3981 m_cpt_dcache_dir_read++;
    3982 #endif
    3983         r_dcache.read_dir( r_dcache_save_paddr.read(),
    3984                            &state,
    3985                            &way,
    3986                            &set,
    3987                            &word );
    3988 
    3989         if ( state == CACHE_SLOT_STATE_VALID )  // inval to be done
     3980        m_cpt_dcache_dir_read++;
     3981#endif
     3982        r_dcache.read_dir(r_dcache_save_paddr.read(),
     3983                          &state,
     3984                          &way,
     3985                          &set,
     3986                          &word);
     3987
     3988        if (state == CACHE_SLOT_STATE_VALID) // inval to be done
    39903989        {
    39913990            r_dcache_xtn_way = way;
    39923991            r_dcache_xtn_set = set;
    3993             r_dcache_fsm      = DCACHE_XTN_DC_INVAL_GO;
    3994         }
    3995         else            // miss : nothing to do
    3996         {
    3997             r_dcache_fsm      = DCACHE_IDLE;
    3998             m_drsp.valid      = true;
     3992            r_dcache_fsm = DCACHE_XTN_DC_INVAL_GO;
     3993        }
     3994        else // miss : nothing to do
     3995        {
     3996            r_dcache_fsm = DCACHE_IDLE;
     3997            m_drsp.valid = true;
    39993998        }
    40003999
    40014000#if DEBUG_DCACHE
    4002 if ( m_debug_dcache_fsm )
    4003 {
    4004     std::cout << "  <PROC " << name()
    4005               << " DCACHE_XTN_DC_INVAL_PA> Test hit in dcache" << std::hex
    4006               << " / PADDR = " << r_dcache_save_paddr.read() << std::dec
    4007               << " / HIT = " << (state == CACHE_SLOT_STATE_VALID)
    4008               << " / SET = " << set
    4009               << " / WAY = " << way << std::endl;
    4010 }
     4001        if (m_debug_dcache_fsm)
     4002        {
     4003            std::cout << "  <PROC " << name()
     4004                << " DCACHE_XTN_DC_INVAL_PA> Test hit in dcache" << std::hex
     4005                << " / PADDR = " << r_dcache_save_paddr.read() << std::dec
     4006                << " / HIT = " << (state == CACHE_SLOT_STATE_VALID)
     4007                << " / SET = " << set
     4008                << " / WAY = " << way << std::endl;
     4009        }
    40114010#endif
    40124011        break;
     
    40144013    ////////////////////////////
    40154014    case DCACHE_XTN_DC_INVAL_GO:  // In this state, we invalidate the cache line
    4016                                               // Blocked if previous cleanup not completed
     4015                                  // Blocked if previous cleanup not completed
    40174016                                  // Test if itlb or dtlb inval is required
    40184017    {
    4019         if ( not r_dcache_cc_send_req.read() ) // blocked until previous cc_send request is sent
    4020         {
    4021             size_t      way        = r_dcache_xtn_way.read();
    4022             size_t      set        = r_dcache_xtn_set.read();
    4023             paddr_t nline      = r_dcache_save_paddr.read() / (m_dcache_words<<2);
     4018        if (not r_dcache_cc_send_req.read()) // blocked until previous cc_send request is sent
     4019        {
     4020            size_t way    = r_dcache_xtn_way.read();
     4021            size_t set    = r_dcache_xtn_set.read();
     4022            paddr_t nline = r_dcache_save_paddr.read() / (m_dcache_words << 2);
    40244023
    40254024#ifdef INSTRUMENTATION
    4026 m_cpt_dcache_dir_write++;
    4027 #endif
    4028             r_dcache.write_dir( way,
    4029                                 set,
    4030                                 CACHE_SLOT_STATE_ZOMBI );
     4025            m_cpt_dcache_dir_write++;
     4026#endif
     4027            r_dcache.write_dir(way,
     4028                               set,
     4029                               CACHE_SLOT_STATE_ZOMBI);
    40314030
    40324031            // request cleanup
     
    40374036
    40384037            // possible itlb & dtlb invalidate
    4039             if ( r_dcache_in_tlb[way*m_dcache_sets+set] )
     4038            if (r_dcache_in_tlb[way * m_dcache_sets + set])
    40404039            {
    40414040                r_dcache_tlb_inval_line = nline;
     
    40434042                r_dcache_fsm_scan_save  = DCACHE_XTN_DC_INVAL_END;
    40444043                r_dcache_fsm            = DCACHE_INVAL_TLB_SCAN;
    4045                 r_dcache_in_tlb[way*m_dcache_sets+set] = false;
    4046             }
    4047             else if ( r_dcache_contains_ptd[way*m_dcache_sets+set] )
     4044                r_dcache_in_tlb[way * m_dcache_sets + set] = false;
     4045            }
     4046            else if (r_dcache_contains_ptd[way * m_dcache_sets + set])
    40484047            {
    40494048                r_itlb.reset();
    40504049                r_dtlb.reset();
    4051                 r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     4050                r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    40524051                r_dcache_fsm = DCACHE_IDLE;
    40534052                m_drsp.valid = true;
     
    40604059
    40614060#if DEBUG_DCACHE
    4062 if ( m_debug_dcache_fsm )
    4063 {
    4064     std::cout << "  <PROC " << name()
    4065               << " DCACHE_XTN_DC_INVAL_GO> Actual dcache inval" << std::hex
    4066               << " / PADDR = " << r_dcache_save_paddr.read() << std::endl;
    4067 }
    4068 #endif
    4069             }
     4061            if (m_debug_dcache_fsm)
     4062            {
     4063                std::cout << "  <PROC " << name()
     4064                    << " DCACHE_XTN_DC_INVAL_GO> Actual dcache inval" << std::hex
     4065                    << " / PADDR = " << r_dcache_save_paddr.read() << std::endl;
     4066            }
     4067#endif
     4068        }
    40704069        break;
    40714070    }
    40724071    //////////////////////////////
    4073     case DCACHE_XTN_DC_INVAL_END:       // send response to processor XTN request
     4072    case DCACHE_XTN_DC_INVAL_END: // send response to processor XTN request
    40744073    {
    40754074        r_dcache_fsm = DCACHE_IDLE;
     
    40884087                                   // when a cleanup is required
    40894088    {
    4090         if ( m_dreq.valid) m_cost_data_miss_frz++;
     4089        if (m_dreq.valid) m_cost_data_miss_frz++;
    40914090
    40924091        // coherence clack request (from DSPIN CLACK)
    4093         if ( r_dcache_clack_req.read() )
     4092        if (r_dcache_clack_req.read())
    40944093        {
    40954094            r_dcache_fsm = DCACHE_CC_CHECK;
     
    40994098
    41004099        // coherence request (from CC_RECEIVE FSM)
    4101         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     4100        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    41024101        {
    41034102            r_dcache_fsm = DCACHE_CC_CHECK;
     
    41064105        }
    41074106
    4108         bool     found = false;
    4109         bool     cleanup = false;
    4110         size_t   way = 0;
    4111         size_t   set = 0;
    4112         paddr_t  victim = 0;
     4107        bool    found = false;
     4108        bool    cleanup = false;
     4109        size_t  way = 0;
     4110        size_t  set = 0;
     4111        paddr_t victim = 0;
    41134112
    41144113#ifdef INSTRUMENTATION
    4115 m_cpt_dcache_dir_read++;
    4116 #endif
    4117         r_dcache.read_select( r_dcache_save_paddr.read(),
    4118                               &victim,
    4119                               &way,
    4120                               &set,
    4121                               &found,
    4122                               &cleanup );
    4123 
    4124         if (  not found )
     4114        m_cpt_dcache_dir_read++;
     4115#endif
     4116        r_dcache.read_select(r_dcache_save_paddr.read(),
     4117                             &victim,
     4118                             &way,
     4119                             &set,
     4120                             &found,
     4121                             &cleanup);
     4122
     4123        if (not found)
    41254124        {
    41264125            break;
     
    41314130            r_dcache_miss_set = set;
    41324131
    4133             if ( cleanup )
    4134             {
    4135                 if ( not r_dcache_cc_send_req.read() )
     4132            if (cleanup)
     4133            {
     4134                if (not r_dcache_cc_send_req.read())
    41364135                {
    4137                     r_dcache_cc_send_req    = true;
    4138                     r_dcache_cc_send_nline  = victim;
    4139                     r_dcache_cc_send_way    = way;
    4140                     r_dcache_cc_send_type   = CC_TYPE_CLEANUP;   
     4136                    r_dcache_cc_send_req   = true;
     4137                    r_dcache_cc_send_nline = victim;
     4138                    r_dcache_cc_send_way   = way;
     4139                    r_dcache_cc_send_type  = CC_TYPE_CLEANUP;   
    41414140
    41424141                }
     
    41474146                }
    41484147
    4149                 r_dcache_miss_clack           = true;
    4150                 r_dcache_fsm                  = DCACHE_MISS_CLEAN;
     4148                r_dcache_miss_clack = true;
     4149                r_dcache_fsm        = DCACHE_MISS_CLEAN;
    41514150            }
    41524151            else
    41534152            {
    4154                 r_dcache_fsm          = DCACHE_MISS_WAIT;
     4153                r_dcache_fsm = DCACHE_MISS_WAIT;
    41554154            }
    41564155
    41574156#if DEBUG_DCACHE
    4158 if ( m_debug_dcache_fsm )
    4159 {
    4160     std::cout << "  <PROC " << name()
    4161               << " DCACHE_MISS_SELECT> Select a slot:" << std::dec
    4162               << " / WAY = "   << way
    4163               << " / SET = "   << set
    4164               << " / PADDR = " << std::hex << r_dcache_save_paddr.read();
    4165     if(cleanup) std::cout << " / VICTIM = " << (victim*m_dcache_words*4) << std::endl;
    4166     else        std::cout << std::endl;
    4167 }
     4157            if (m_debug_dcache_fsm)
     4158            {
     4159                std::cout << "  <PROC " << name()
     4160                    << " DCACHE_MISS_SELECT> Select a slot:" << std::dec
     4161                    << " / WAY = "   << way
     4162                    << " / SET = "   << set
     4163                    << " / PADDR = " << std::hex << r_dcache_save_paddr.read();
     4164                if (cleanup) std::cout << " / VICTIM = " << (victim*m_dcache_words*4) << std::endl;
     4165                else        std::cout << std::endl;
     4166            }
    41684167#endif
    41694168        } // end found
     
    41714170    }
    41724171    ///////////////////////
    4173     case DCACHE_MISS_CLEAN:             // switch the slot to ZOMBI state
     4172    case DCACHE_MISS_CLEAN:     // switch the slot to ZOMBI state
    41744173                                // and possibly request itlb or dtlb invalidate
    41754174    {
    4176         if ( m_dreq.valid) m_cost_data_miss_frz++;
    4177 
    4178         size_t  way  = r_dcache_miss_way.read();
    4179         size_t  set  = r_dcache_miss_set.read();
     4175        if (m_dreq.valid) m_cost_data_miss_frz++;
     4176
     4177        size_t way = r_dcache_miss_way.read();
     4178        size_t set = r_dcache_miss_set.read();
    41804179
    41814180#ifdef INSTRUMENTATION
    4182 m_cpt_dcache_dir_read++;
    4183 #endif
    4184         r_dcache.write_dir( way,
    4185                             set,
    4186                             CACHE_SLOT_STATE_ZOMBI );
     4181        m_cpt_dcache_dir_read++;
     4182#endif
     4183        r_dcache.write_dir(way,
     4184                           set,
     4185                           CACHE_SLOT_STATE_ZOMBI);
    41874186#if DEBUG_DCACHE
    4188 if ( m_debug_dcache_fsm )
    4189 {
    4190     std::cout << "  <PROC " << name()
    4191               << " DCACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
    4192               << " / way = "   << way
    4193               << " / set = "   << set << std::endl;
    4194 }
     4187        if (m_debug_dcache_fsm)
     4188        {
     4189            std::cout << "  <PROC " << name()
     4190                << " DCACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
     4191                << " / way = "   << way
     4192                << " / set = "   << set << std::endl;
     4193        }
    41954194#endif
    41964195        // if selective itlb & dtlb invalidate are required
    41974196        // the miss response is not handled before invalidate completed
    4198         if ( r_dcache_in_tlb[way*m_dcache_sets+set] )
    4199         {
    4200             r_dcache_in_tlb[way*m_dcache_sets+set] = false;
    4201 
    4202             if( not r_dcache_cleanup_victim_req.read() )
    4203                 r_dcache_tlb_inval_line  = r_dcache_cc_send_nline.read();
     4197        if (r_dcache_in_tlb[way * m_dcache_sets + set])
     4198        {
     4199            r_dcache_in_tlb[way * m_dcache_sets + set] = false;
     4200
     4201            if (not r_dcache_cleanup_victim_req.read())
     4202                r_dcache_tlb_inval_line = r_dcache_cc_send_nline.read();
    42044203            else
    42054204                r_dcache_tlb_inval_line = r_dcache_cleanup_victim_nline.read();
    42064205
    4207             r_dcache_tlb_inval_set   = 0;
    4208             r_dcache_fsm_scan_save   = DCACHE_MISS_WAIT;
    4209             r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
    4210         }
    4211         else if ( r_dcache_contains_ptd[way*m_dcache_sets+set] )
     4206            r_dcache_tlb_inval_set = 0;
     4207            r_dcache_fsm_scan_save = DCACHE_MISS_WAIT;
     4208            r_dcache_fsm           = DCACHE_INVAL_TLB_SCAN;
     4209        }
     4210        else if (r_dcache_contains_ptd[way * m_dcache_sets + set])
    42124211        {
    42134212            r_itlb.reset();
    42144213            r_dtlb.reset();
    4215             r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     4214            r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    42164215            r_dcache_fsm = DCACHE_MISS_WAIT;
    42174216        }
     
    42234222    }
    42244223    //////////////////////
    4225     case DCACHE_MISS_WAIT:      // waiting the response to a miss request from VCI_RSP FSM
     4224    case DCACHE_MISS_WAIT: // waiting the response to a miss request from VCI_RSP FSM
    42264225                            // This state is in charge of error signaling
    42274226                            // There is 5 types of error depending on the requester
    42284227    {
    4229         if ( m_dreq.valid) m_cost_data_miss_frz++;
     4228        if (m_dreq.valid) m_cost_data_miss_frz++;
    42304229
    42314230        // send cleanup victim request
    4232         if ( r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read() )
     4231        if (r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read())
    42334232        {
    42344233            r_dcache_cc_send_req        = true;
     
    42404239
    42414240        // coherence clack request (from DSPIN CLACK)
    4242         if ( r_dcache_clack_req.read() )
     4241        if (r_dcache_clack_req.read())
    42434242        {
    42444243            r_dcache_fsm = DCACHE_CC_CHECK;
     
    42484247
    42494248        // coherence request (from CC_RECEIVE FSM)
    4250         if ( r_cc_receive_dcache_req.read() and
     4249        if (r_cc_receive_dcache_req.read() and
    42514250             not r_dcache_cc_send_req.read() and
    42524251             not r_dcache_cleanup_victim_req.read())
     
    42574256        }
    42584257
    4259         if ( r_vci_rsp_data_error.read() )                      // bus error
    4260         {
    4261             switch ( r_dcache_miss_type.read() )
     4258        if (r_vci_rsp_data_error.read()) // bus error
     4259        {
     4260            switch (r_dcache_miss_type.read())
    42624261            {
    42634262                case PROC_MISS:
    42644263                {
    4265                     r_mmu_detr            = MMU_READ_DATA_ILLEGAL_ACCESS;
    4266                     r_mmu_dbvar           = r_dcache_save_vaddr.read();
    4267                     m_drsp.valid            = true;
    4268                     m_drsp.error            = true;
    4269                     r_dcache_fsm          = DCACHE_IDLE;
     4264                    r_mmu_detr   = MMU_READ_DATA_ILLEGAL_ACCESS;
     4265                    r_mmu_dbvar  = r_dcache_save_vaddr.read();
     4266                    m_drsp.valid = true;
     4267                    m_drsp.error = true;
     4268                    r_dcache_fsm = DCACHE_IDLE;
    42704269                    break;
    42714270                }
    42724271                case PTE1_MISS:
    42734272                {
    4274                     if ( r_dcache_tlb_ins.read() )
     4273                    if (r_dcache_tlb_ins.read())
    42754274                    {
    4276                         r_mmu_ietr              = MMU_READ_PT1_ILLEGAL_ACCESS;
    4277                         r_mmu_ibvar             = r_dcache_tlb_vaddr.read();
    4278                         r_icache_tlb_miss_req   = false;
    4279                         r_icache_tlb_rsp_error  = true;
     4275                        r_mmu_ietr             = MMU_READ_PT1_ILLEGAL_ACCESS;
     4276                        r_mmu_ibvar            = r_dcache_tlb_vaddr.read();
     4277                        r_icache_tlb_miss_req  = false;
     4278                        r_icache_tlb_rsp_error = true;
    42804279                    }
    42814280                    else
    42824281                    {
    4283                         r_mmu_detr              = MMU_READ_PT1_ILLEGAL_ACCESS;
    4284                         r_mmu_dbvar             = r_dcache_tlb_vaddr.read();
    4285                         m_drsp.valid              = true;
    4286                         m_drsp.error              = true;
     4282                        r_mmu_detr   = MMU_READ_PT1_ILLEGAL_ACCESS;
     4283                        r_mmu_dbvar  = r_dcache_tlb_vaddr.read();
     4284                        m_drsp.valid = true;
     4285                        m_drsp.error = true;
    42874286                    }
    4288                     r_dcache_fsm                = DCACHE_IDLE;
     4287                    r_dcache_fsm = DCACHE_IDLE;
    42894288                    break;
    42904289                }
    42914290                case PTE2_MISS:
    42924291                {
    4293                     if ( r_dcache_tlb_ins.read() )
     4292                    if (r_dcache_tlb_ins.read())
    42944293                    {
    4295                         r_mmu_ietr              = MMU_READ_PT2_ILLEGAL_ACCESS;
    4296                         r_mmu_ibvar             = r_dcache_tlb_vaddr.read();
    4297                         r_icache_tlb_miss_req   = false;
    4298                         r_icache_tlb_rsp_error  = true;
     4294                        r_mmu_ietr             = MMU_READ_PT2_ILLEGAL_ACCESS;
     4295                        r_mmu_ibvar            = r_dcache_tlb_vaddr.read();
     4296                        r_icache_tlb_miss_req  = false;
     4297                        r_icache_tlb_rsp_error = true;
    42994298                    }
    43004299                    else
    43014300                    {
    4302                         r_mmu_detr              = MMU_READ_PT2_ILLEGAL_ACCESS;
    4303                         r_mmu_dbvar             = r_dcache_tlb_vaddr.read();
    4304                         m_drsp.valid              = true;
    4305                         m_drsp.error              = true;
     4301                        r_mmu_detr   = MMU_READ_PT2_ILLEGAL_ACCESS;
     4302                        r_mmu_dbvar  = r_dcache_tlb_vaddr.read();
     4303                        m_drsp.valid  = true;
     4304                        m_drsp.error  = true;
    43064305                    }
    4307                     r_dcache_fsm                = DCACHE_IDLE;
     4306                    r_dcache_fsm = DCACHE_IDLE;
    43084307                    break;
    43094308                }
     
    43114310            r_vci_rsp_data_error = false;
    43124311        }
    4313         else if ( r_vci_rsp_fifo_dcache.rok() )         // valid response available
     4312        else if (r_vci_rsp_fifo_dcache.rok()) // valid response available
    43144313        {
    43154314            r_dcache_miss_word = 0;
    4316                 r_dcache_fsm       = DCACHE_MISS_DATA_UPDT;
     4315            r_dcache_fsm       = DCACHE_MISS_DATA_UPDT;
    43174316        }
    43184317        break;
    43194318    }
    43204319    //////////////////////////
    4321     case DCACHE_MISS_DATA_UPDT:   // update the dcache (one word per cycle)
    4322     {
    4323         if ( m_dreq.valid) m_cost_data_miss_frz++;
    4324 
    4325         if ( r_vci_rsp_fifo_dcache.rok() )      // one word available
     4320    case DCACHE_MISS_DATA_UPDT:  // update the dcache (one word per cycle)
     4321    {
     4322        if (m_dreq.valid) m_cost_data_miss_frz++;
     4323
     4324        if (r_vci_rsp_fifo_dcache.rok()) // one word available
    43264325        {
    43274326#ifdef INSTRUMENTATION
    4328 m_cpt_dcache_data_write++;
    4329 #endif
    4330                 r_dcache.write( r_dcache_miss_way.read(),
    4331                                 r_dcache_miss_set.read(),
    4332                                 r_dcache_miss_word.read(),
    4333                                 r_vci_rsp_fifo_dcache.read() );
     4327            m_cpt_dcache_data_write++;
     4328#endif
     4329            r_dcache.write(r_dcache_miss_way.read(),
     4330                               r_dcache_miss_set.read(),
     4331                               r_dcache_miss_word.read(),
     4332                               r_vci_rsp_fifo_dcache.read());
    43344333#if DEBUG_DCACHE
    4335 if ( m_debug_dcache_fsm )
    4336 {
    4337     std::cout << "  <PROC " << name()
    4338               << " DCACHE_MISS_DATA_UPDT> Write one word:"
    4339               << " / DATA = "  << std::hex << r_vci_rsp_fifo_dcache.read()
    4340               << " / WAY = "   << std::dec << r_dcache_miss_way.read()
    4341               << " / SET = "   << r_dcache_miss_set.read()
    4342               << " / WORD = "  << r_dcache_miss_word.read() << std::endl;
    4343 }
     4334            if (m_debug_dcache_fsm)
     4335            {
     4336                std::cout << "  <PROC " << name()
     4337                    << " DCACHE_MISS_DATA_UPDT> Write one word:"
     4338                    << " / DATA = "  << std::hex << r_vci_rsp_fifo_dcache.read()
     4339                    << " / WAY = "   << std::dec << r_dcache_miss_way.read()
     4340                    << " / SET = "   << r_dcache_miss_set.read()
     4341                    << " / WORD = "  << r_dcache_miss_word.read() << std::endl;
     4342            }
    43444343#endif
    43454344            vci_rsp_fifo_dcache_get = true;
    43464345            r_dcache_miss_word = r_dcache_miss_word.read() + 1;
    43474346
    4348             if ( r_dcache_miss_word.read() == (m_dcache_words-1) ) // last word
     4347            if (r_dcache_miss_word.read() == (m_dcache_words - 1)) // last word
    43494348            {
    43504349                r_dcache_fsm = DCACHE_MISS_DIR_UPDT;
     
    43624361                                //   to ZOMBI state, and send a cleanup request.
    43634362    {
    4364         if ( m_dreq.valid) m_cost_data_miss_frz++;
     4363        if (m_dreq.valid) m_cost_data_miss_frz++;
    43654364
    43664365        // send cleanup victim request
    4367         if ( r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read() )
     4366        if (r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read())
    43684367        {
    43694368            r_dcache_cc_send_req        = true;
     
    43754374
    43764375        // coherence clack request (from DSPIN CLACK)
    4377         if ( r_dcache_clack_req.read() )
     4376        if (r_dcache_clack_req.read())
    43784377        {
    43794378            r_dcache_fsm = DCACHE_CC_CHECK;
     
    43834382
    43844383        // coherence request (from CC_RECEIVE FSM)
    4385         if ( r_cc_receive_dcache_req.read() and
     4384        if (r_cc_receive_dcache_req.read() and
    43864385             not r_dcache_cc_send_req.read() and
    4387              not r_dcache_cleanup_victim_req.read() )
     4386             not r_dcache_cleanup_victim_req.read())
    43884387        {
    43894388            r_dcache_fsm = DCACHE_CC_CHECK;
     
    43924391        }
    43934392
    4394         if ( not r_dcache_miss_clack.read() )  // waiting cleanup acknowledge
    4395         {
    4396             if ( r_dcache_miss_inval.read() ) // switch slot to ZOMBI state, and new cleanup
    4397             {
    4398                 if ( not r_dcache_cc_send_req.read() ) // blocked until previous request sent
     4393        if (not r_dcache_miss_clack.read())  // waiting cleanup acknowledge
     4394        {
     4395            if (r_dcache_miss_inval.read()) // switch slot to ZOMBI state, and new cleanup
     4396            {
     4397                if (not r_dcache_cc_send_req.read()) // blocked until previous request sent
    43994398                {
    44004399                    r_dcache_miss_inval     = false;
    44014400                    // request cleanup
    44024401                    r_dcache_cc_send_req   = true;
    4403                     r_dcache_cc_send_nline = r_dcache_save_paddr.read()/(m_dcache_words<<2);
     4402                    r_dcache_cc_send_nline = r_dcache_save_paddr.read() / (m_dcache_words << 2);
    44044403                    r_dcache_cc_send_way   = r_dcache_miss_way.read();
    44054404                    r_dcache_cc_send_type  = CC_TYPE_CLEANUP;
    44064405
    44074406#ifdef INSTRUMENTATION
    4408 m_cpt_dcache_dir_write++;
     4407                    m_cpt_dcache_dir_write++;
    44094408#endif
    44104409                    r_dcache.write_dir( r_dcache_save_paddr.read(),
     
    44134412                                        CACHE_SLOT_STATE_ZOMBI );
    44144413#if DEBUG_DCACHE
    4415 if ( m_debug_dcache_fsm )
    4416 std::cout << "  <PROC " << name()
    4417           << " DCACHE_MISS_DIR_UPDT> Switch slot to ZOMBI state"
    4418           << " PADDR = " << std::hex << r_dcache_save_paddr.read()
    4419           << " / WAY = "   << std::dec << r_dcache_miss_way.read()
    4420           << " / SET = "   << r_dcache_miss_set.read() << std::endl;
     4414                    if (m_debug_dcache_fsm)
     4415                        std::cout << "  <PROC " << name()
     4416                            << " DCACHE_MISS_DIR_UPDT> Switch slot to ZOMBI state"
     4417                            << " PADDR = " << std::hex << r_dcache_save_paddr.read()
     4418                            << " / WAY = "   << std::dec << r_dcache_miss_way.read()
     4419                            << " / SET = "   << r_dcache_miss_set.read() << std::endl;
    44214420#endif
    44224421                }
     
    44284427
    44294428#ifdef INSTRUMENTATION
    4430 m_cpt_dcache_dir_write++;
    4431 #endif
    4432                 r_dcache.write_dir( r_dcache_save_paddr.read(),
    4433                                     r_dcache_miss_way.read(),
    4434                                     r_dcache_miss_set.read(),
    4435                                     CACHE_SLOT_STATE_VALID );
     4429                m_cpt_dcache_dir_write++;
     4430#endif
     4431                r_dcache.write_dir(r_dcache_save_paddr.read(),
     4432                                   r_dcache_miss_way.read(),
     4433                                   r_dcache_miss_set.read(),
     4434                                   CACHE_SLOT_STATE_VALID);
    44364435
    44374436#if DEBUG_DCACHE
    4438 if ( m_debug_dcache_fsm )
    4439 std::cout << "  <PROC " << name()
    4440           << " DCACHE_MISS_DIR_UPDT> Switch slot to VALID state"
    4441           << " PADDR = " << std::hex << r_dcache_save_paddr.read()
    4442           << " / WAY = "   << std::dec << r_dcache_miss_way.read()
    4443           << " / SET = "   << r_dcache_miss_set.read() << std::endl;
     4437                if (m_debug_dcache_fsm)
     4438                    std::cout << "  <PROC " << name()
     4439                        << " DCACHE_MISS_DIR_UPDT> Switch slot to VALID state"
     4440                        << " PADDR = " << std::hex << r_dcache_save_paddr.read()
     4441                        << " / WAY = "   << std::dec << r_dcache_miss_way.read()
     4442                        << " / SET = "   << r_dcache_miss_set.read() << std::endl;
    44444443#endif
    44454444                // reset directory extension
    44464445                size_t way = r_dcache_miss_way.read();
    44474446                size_t set = r_dcache_miss_set.read();
    4448                 r_dcache_in_tlb[way*m_dcache_sets+set] = false;
    4449                 r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     4447                r_dcache_in_tlb[way * m_dcache_sets + set] = false;
     4448                r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    44504449            }
    44514450            if      (r_dcache_miss_type.read()==PTE1_MISS) r_dcache_fsm = DCACHE_TLB_PTE1_GET;
     
    44594458    {
    44604459        // coherence clack request (from DSPIN CLACK)
    4461         if ( r_dcache_clack_req.read() )
     4460        if (r_dcache_clack_req.read())
    44624461        {
    44634462            r_dcache_fsm = DCACHE_CC_CHECK;
     
    44674466
    44684467        // coherence request (from CC_RECEIVE FSM)
    4469         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     4468        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    44704469        {
    44714470            r_dcache_fsm = DCACHE_CC_CHECK;
     
    44744473        }
    44754474
    4476         if ( r_vci_rsp_data_error.read() )      // bus error
    4477         {
    4478             if(r_dcache_vci_unc_write.read())
    4479                 r_mmu_detr           = MMU_WRITE_DATA_ILLEGAL_ACCESS;
     4475        if (r_vci_rsp_data_error.read()) // bus error
     4476        {
     4477            if (r_dcache_vci_unc_write.read())
     4478                r_mmu_detr = MMU_WRITE_DATA_ILLEGAL_ACCESS;
    44804479            else
    4481                 r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
     4480                r_mmu_detr = MMU_READ_DATA_ILLEGAL_ACCESS;
    44824481               
    44834482            r_mmu_dbvar          = m_dreq.addr;
     
    44884487            break;
    44894488        }
    4490             else if ( r_vci_rsp_fifo_dcache.rok() )     // data available
    4491             {
     4489        else if (r_vci_rsp_fifo_dcache.rok())     // data available
     4490        {
    44924491            // consume data
    44934492            vci_rsp_fifo_dcache_get = true;
     
    44954494
    44964495            // acknowledge the processor request if it has not been modified
    4497             if ( m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()) )
    4498             {
    4499                     m_drsp.valid        = true;
    4500                 m_drsp.error        = false;
    4501                     m_drsp.rdata        = r_vci_rsp_fifo_dcache.read();
    4502             }
    4503             }
     4496            if (m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()))
     4497            {
     4498                m_drsp.valid = true;
     4499                m_drsp.error = false;
     4500                m_drsp.rdata = r_vci_rsp_fifo_dcache.read();
     4501            }
     4502        }
    45044503        break;
    45054504    }
     
    45084507    {
    45094508        // coherence clack request (from DSPIN CLACK)
    4510         if ( r_dcache_clack_req.read() )
     4509        if (r_dcache_clack_req.read())
    45114510        {
    45124511            r_dcache_fsm = DCACHE_CC_CHECK;
     
    45164515
    45174516        // coherence request (from CC_RECEIVE FSM)
    4518         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     4517        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    45194518        {
    45204519            r_dcache_fsm = DCACHE_CC_CHECK;
     
    45234522        }
    45244523
    4525         if ( r_vci_rsp_data_error.read() )      // bus error
     4524        if (r_vci_rsp_data_error.read()) // bus error
    45264525        {
    45274526            r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
     
    45334532            break;
    45344533        }
    4535             else if ( r_vci_rsp_fifo_dcache.rok() )     // data available
    4536             {
     4534        else if (r_vci_rsp_fifo_dcache.rok())     // data available
     4535        {
    45374536            // consume data
    45384537            vci_rsp_fifo_dcache_get = true;
    45394538
    4540             if(r_dcache_ll_rsp_count.read() == 0) // first flit
     4539            if (r_dcache_ll_rsp_count.read() == 0) // first flit
    45414540            {
    45424541                // set key value in llsc reservation buffer
    45434542                r_dcache_llsc_key     = r_vci_rsp_fifo_dcache.read();
    4544                 r_dcache_ll_rsp_count = r_dcache_ll_rsp_count.read() + 1 ;
     4543                r_dcache_ll_rsp_count = r_dcache_ll_rsp_count.read() + 1;
    45454544            }
    45464545            else                                  // last flit
    45474546            {
    45484547                // acknowledge the processor request if it has not been modified
    4549                 if ( m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()) )
     4548                if (m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()))
    45504549                {
    4551                     m_drsp.valid        = true;
    4552                     m_drsp.error        = false;
    4553                     m_drsp.rdata        = r_vci_rsp_fifo_dcache.read();
     4550                    m_drsp.valid = true;
     4551                    m_drsp.error = false;
     4552                    m_drsp.rdata = r_vci_rsp_fifo_dcache.read();
    45544553                }
    45554554                r_dcache_fsm = DCACHE_IDLE;
    45564555            }
    4557             }
     4556        }
    45584557        break;
    45594558    }
    45604559    ////////////////////
    4561     case DCACHE_SC_WAIT:        // waiting VCI response to a SC transaction
     4560    case DCACHE_SC_WAIT: // waiting VCI response to a SC transaction
    45624561    {
    45634562        // coherence clack request (from DSPIN CLACK)
    4564         if ( r_dcache_clack_req.read() )
     4563        if (r_dcache_clack_req.read())
    45654564        {
    45664565            r_dcache_fsm = DCACHE_CC_CHECK;
     
    45704569
    45714570        // coherence request (from CC_RECEIVE FSM)
    4572         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     4571        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    45734572        {
    45744573            r_dcache_fsm = DCACHE_CC_CHECK;
     
    45774576        }
    45784577
    4579         if ( r_vci_rsp_data_error.read() )              // bus error
     4578        if (r_vci_rsp_data_error.read()) // bus error
    45804579        {
    45814580            r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
     
    45874586            break;
    45884587        }
    4589             else if ( r_vci_rsp_fifo_dcache.rok() ) // response available
    4590             {
     4588        else if (r_vci_rsp_fifo_dcache.rok()) // response available
     4589        {
    45914590            // consume response
    45924591            vci_rsp_fifo_dcache_get = true;
     
    45944593            m_drsp.rdata            = r_vci_rsp_fifo_dcache.read();
    45954594            r_dcache_fsm            = DCACHE_IDLE;
    4596             }
     4595        }
    45974596        break;
    45984597    }
    45994598    //////////////////////////
    4600     case DCACHE_DIRTY_GET_PTE:          // This sub_fsm set the PTE Dirty bit in memory
    4601                                     // before handling a processor WRITE or SC request
    4602                                     // Input argument is r_dcache_dirty_paddr
    4603                                     // In this first state, we get PTE value in dcache
    4604                                     // and post a CAS request to CMD FSM
     4599    case DCACHE_DIRTY_GET_PTE:  // This sub_fsm set the PTE Dirty bit in memory
     4600                                // before handling a processor WRITE or SC request
     4601                                // Input argument is r_dcache_dirty_paddr
     4602                                // In this first state, we get PTE value in dcache
     4603                                // and post a CAS request to CMD FSM
    46054604    {
    46064605        // get PTE in dcache
     
    46124611
    46134612#ifdef INSTRUMENTATION
    4614 m_cpt_dcache_data_read++;
    4615 m_cpt_dcache_dir_read++;
    4616 #endif
    4617         r_dcache.read( r_dcache_dirty_paddr.read(),
    4618                        &pte,
    4619                        &way,
    4620                        &set,
    4621                        &word,
    4622                        &state );
     4613        m_cpt_dcache_data_read++;
     4614        m_cpt_dcache_dir_read++;
     4615#endif
     4616        r_dcache.read(r_dcache_dirty_paddr.read(),
     4617                      &pte,
     4618                      &way,
     4619                      &set,
     4620                      &word,
     4621                      &state);
    46234622
    46244623        assert( (state == CACHE_SLOT_STATE_VALID) and
     
    46264625
    46274626        // request CAS transaction to CMD_FSM
    4628         r_dcache_dirty_way  = way;
    4629         r_dcache_dirty_set  = set;
     4627        r_dcache_dirty_way = way;
     4628        r_dcache_dirty_set = set;
    46304629
    46314630        // check llsc reservation buffer
    4632         if (r_dcache_llsc_paddr.read() == r_dcache_dirty_paddr.read() )
     4631        if (r_dcache_llsc_paddr.read() == r_dcache_dirty_paddr.read())
    46334632            r_dcache_llsc_valid = false;
    46344633
     
    46414640
    46424641#if DEBUG_DCACHE
    4643 if ( m_debug_dcache_fsm )
    4644 {
    4645     std::cout << "  <PROC " << name()
    4646               << " DCACHE_DIRTY_GET_PTE> CAS request" << std::hex
    4647               << " / PTE_PADDR = " << r_dcache_dirty_paddr.read()
    4648               << " / PTE_VALUE = " << pte << std::dec
    4649               << " / SET = " << set
    4650               << " / WAY = " << way << std::endl;
    4651 }
     4642        if (m_debug_dcache_fsm)
     4643        {
     4644            std::cout << "  <PROC " << name()
     4645                << " DCACHE_DIRTY_GET_PTE> CAS request" << std::hex
     4646                << " / PTE_PADDR = " << r_dcache_dirty_paddr.read()
     4647                << " / PTE_VALUE = " << pte << std::dec
     4648                << " / SET = " << set
     4649                << " / WAY = " << way << std::endl;
     4650        }
    46524651#endif
    46534652        break;
    46544653    }
    46554654    ///////////////////////
    4656     case DCACHE_DIRTY_WAIT:         // wait completion of CAS for PTE Dirty bit,
    4657                                     // and return to IDLE state when response is received.
    4658                                     // we don't care if the CAS is a failure:
    4659                                     // - if the CAS is a success, the coherence mechanism
    4660                                     //   updates the local copy.
    4661                                     // - if the CAS is a failure, we just retry the write.
     4655    case DCACHE_DIRTY_WAIT:    // wait completion of CAS for PTE Dirty bit,
     4656                               // and return to IDLE state when response is received.
     4657                               // we don't care if the CAS is a failure:
     4658                               // - if the CAS is a success, the coherence mechanism
     4659                               //   updates the local copy.
     4660                               // - if the CAS is a failure, we just retry the write.
    46624661    {
    46634662        // coherence clack request (from DSPIN CLACK)
    4664         if ( r_dcache_clack_req.read() )
     4663        if (r_dcache_clack_req.read())
    46654664        {
    46664665            r_dcache_fsm = DCACHE_CC_CHECK;
     
    46704669
    46714670        // coherence request (from CC_RECEIVE FSM)
    4672         if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
     4671        if (r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
    46734672        {
    46744673            r_dcache_fsm = DCACHE_CC_CHECK;
     
    46774676        }
    46784677
    4679         if ( r_vci_rsp_data_error.read() )      // bus error
     4678        if (r_vci_rsp_data_error.read())      // bus error
    46804679        {
    46814680            std::cout << "BUS ERROR in DCACHE_DIRTY_WAIT state" << std::endl;
     
    46834682            exit(0);
    46844683        }
    4685         else if ( r_vci_rsp_fifo_dcache.rok() ) // response available
     4684        else if (r_vci_rsp_fifo_dcache.rok()) // response available
    46864685        {
    46874686            vci_rsp_fifo_dcache_get = true;
     
    46894688
    46904689#if DEBUG_DCACHE
    4691 if ( m_debug_dcache_fsm )
    4692 {
    4693     std::cout << "  <PROC " << name()
    4694               << " DCACHE_DIRTY_WAIT> CAS completed" << std::endl;
    4695 }
     4690            if (m_debug_dcache_fsm)
     4691            {
     4692                std::cout << "  <PROC " << name()
     4693                    << " DCACHE_DIRTY_WAIT> CAS completed" << std::endl;
     4694            }
    46964695#endif
    46974696        }
     
    47074706                            // The return state is defined in r_dcache_fsm_cc_save
    47084707    {
    4709         paddr_t  paddr = r_cc_receive_dcache_nline.read() * m_dcache_words * 4;
    4710         paddr_t  mask = ~((m_dcache_words<<2)-1);
     4708        paddr_t paddr = r_cc_receive_dcache_nline.read() * m_dcache_words * 4;
     4709        paddr_t mask = ~((m_dcache_words << 2) - 1);
    47114710
    47124711        // CLACK handler
    47134712        // We switch the directory slot to EMPTY state and reset
    47144713        // r_dcache_miss_clack if the cleanup ack is matching a pending miss.
    4715         if ( r_dcache_clack_req.read() )
    4716         {
    4717             if ( m_dreq.valid ) m_cost_data_miss_frz++;
     4714        if (r_dcache_clack_req.read())
     4715        {
     4716            if (m_dreq.valid ) m_cost_data_miss_frz++;
    47184717
    47194718#ifdef INSTRUMENTATION
    4720 m_cpt_dcache_dir_write++;
    4721 #endif
    4722             r_dcache.write_dir( 0,
    4723                                 r_dcache_clack_way.read(),
    4724                                 r_dcache_clack_set.read(),
    4725                                 CACHE_SLOT_STATE_EMPTY);
    4726 
    4727             if ( (r_dcache_miss_set.read() == r_dcache_clack_set.read()) and
    4728                  (r_dcache_miss_way.read() == r_dcache_clack_way.read()) )
     4719            m_cpt_dcache_dir_write++;
     4720#endif
     4721            r_dcache.write_dir(0,
     4722                               r_dcache_clack_way.read(),
     4723                               r_dcache_clack_set.read(),
     4724                               CACHE_SLOT_STATE_EMPTY);
     4725
     4726            if ((r_dcache_miss_set.read() == r_dcache_clack_set.read()) and
     4727                (r_dcache_miss_way.read() == r_dcache_clack_way.read()))
    47294728            {
    47304729                  r_dcache_miss_clack = false;
     
    47374736
    47384737#if DEBUG_DCACHE
    4739 if ( m_debug_dcache_fsm )
    4740 {
    4741     std::cout << "  <PROC " << name()
    4742               << " DCACHE_CC_CHECK> CLACK for PADDR " << paddr
    4743               << " Switch slot to EMPTY state : "
    4744               << " set = " << r_dcache_clack_set.read()
    4745               << " / way = " << r_dcache_clack_way.read() << std::endl;
    4746 }
     4738            if (m_debug_dcache_fsm)
     4739            {
     4740                std::cout << "  <PROC " << name()
     4741                    << " DCACHE_CC_CHECK> CLACK for PADDR " << paddr
     4742                    << " Switch slot to EMPTY state : "
     4743                    << " set = " << r_dcache_clack_set.read()
     4744                    << " / way = " << r_dcache_clack_way.read() << std::endl;
     4745            }
    47474746#endif
    47484747            break;
     
    47544753        // Match between MISS address and CC address
    47554754        if (r_cc_receive_dcache_req.read() and
    4756           ((r_dcache_fsm_cc_save == DCACHE_MISS_SELECT  )  or
    4757            (r_dcache_fsm_cc_save == DCACHE_MISS_WAIT    )  or
     4755          ((r_dcache_fsm_cc_save == DCACHE_MISS_SELECT)  or
     4756           (r_dcache_fsm_cc_save == DCACHE_MISS_WAIT)  or
    47584757           (r_dcache_fsm_cc_save == DCACHE_MISS_DIR_UPDT)) and
    47594758          ((r_dcache_vci_paddr.read() & mask) == (paddr & mask))) // matching
     
    47664765            if (r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)
    47674766            {
    4768                 r_dcache_fsm        = DCACHE_CC_UPDT;
    4769                 r_dcache_cc_word    = r_cc_receive_word_idx.read();
     4767                r_dcache_fsm     = DCACHE_CC_UPDT;
     4768                r_dcache_cc_word = r_cc_receive_word_idx.read();
    47704769
    47714770                // just pop the fifo , don't write in icache
     
    47804779
    47814780#if DEBUG_DCACHE
    4782 if ( m_debug_dcache_fsm )
    4783 {
    4784     std::cout << "  <PROC " << name()
    4785               << " DCACHE_CC_CHECK> Coherence request matching a pending miss:"
    4786               << " PADDR = " << std::hex << paddr << std::endl;
    4787 }
     4781            if (m_debug_dcache_fsm)
     4782            {
     4783                std::cout << "  <PROC " << name()
     4784                    << " DCACHE_CC_CHECK> Coherence request matching a pending miss:"
     4785                    << " PADDR = " << std::hex << paddr << std::endl;
     4786            }
    47884787#endif
    47894788        }
     
    47974796
    47984797#ifdef INSTRUMENTATION
    4799 m_cpt_dcache_dir_read++;
    4800 #endif
    4801         r_dcache.read_dir( paddr,
    4802                            &state,
    4803                            &way,
    4804                            &set,
    4805                            &word ); // unused
     4798        m_cpt_dcache_dir_read++;
     4799#endif
     4800        r_dcache.read_dir(paddr,
     4801                          &state,
     4802                          &way,
     4803                          &set,
     4804                          &word); // unused
    48064805
    48074806        r_dcache_cc_way = way;
    48084807        r_dcache_cc_set = set;
    48094808
    4810         if ( state == CACHE_SLOT_STATE_VALID) // hit
     4809        if (state == CACHE_SLOT_STATE_VALID) // hit
    48114810        {
    48124811            // need to update the cache state
     
    48174816                r_dcache_cc_word       = r_cc_receive_word_idx.read();
    48184817            }
    4819             else if ( r_cc_receive_dcache_type.read() == CC_TYPE_INVAL ) // hit inval
    4820             {
    4821                 r_dcache_fsm           = DCACHE_CC_INVAL;
     4818            else if (r_cc_receive_dcache_type.read() == CC_TYPE_INVAL) // hit inval
     4819            {
     4820                r_dcache_fsm = DCACHE_CC_INVAL;
    48224821            }
    48234822        }
     
    48254824        {
    48264825            // multicast acknowledgement required in case of update
    4827             if(r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)
    4828             {
    4829                 r_dcache_fsm           = DCACHE_CC_UPDT;
    4830                 r_dcache_cc_word       = r_cc_receive_word_idx.read();
     4826            if (r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)
     4827            {
     4828                r_dcache_fsm     = DCACHE_CC_UPDT;
     4829                r_dcache_cc_word = r_cc_receive_word_idx.read();
    48314830
    48324831                // just pop the fifo , don't write in icache
     
    48364835            {
    48374836                r_cc_receive_dcache_req = false;
    4838                 r_dcache_fsm            = r_dcache_fsm_cc_save.read();
     4837                r_dcache_fsm = r_dcache_fsm_cc_save.read();
    48394838            }
    48404839        }
    48414840
    48424841#if DEBUG_DCACHE
    4843 if ( m_debug_dcache_fsm )
    4844 {
    4845     std::cout << "  <PROC " << name()
    4846               << " DCACHE_CC_CHECK> Coherence request received:"
    4847               << " PADDR = " << std::hex << paddr
    4848               << " / TYPE = " << std::dec << r_cc_receive_dcache_type.read()
    4849               << " / HIT = " << (state == CACHE_SLOT_STATE_VALID) << std::endl;
    4850 }
     4842        if (m_debug_dcache_fsm)
     4843        {
     4844            std::cout << "  <PROC " << name()
     4845                << " DCACHE_CC_CHECK> Coherence request received:"
     4846                << " PADDR = " << std::hex << paddr
     4847                << " / TYPE = " << std::dec << r_cc_receive_dcache_type.read()
     4848                << " / HIT = " << (state == CACHE_SLOT_STATE_VALID) << std::endl;
     4849        }
    48514850#endif
    48524851
     
    48584857                          // TLBs
    48594858    {
    4860         size_t way    = r_dcache_cc_way.read();
    4861         size_t set    = r_dcache_cc_set.read();
    4862 
    4863         if ( r_dcache_in_tlb[way*m_dcache_sets+set] )       // selective TLB inval
    4864         {
    4865             r_dcache_in_tlb[way*m_dcache_sets+set] = false;
    4866             r_dcache_tlb_inval_line  = r_cc_receive_dcache_nline.read();
    4867             r_dcache_tlb_inval_set   = 0;
    4868             r_dcache_fsm_scan_save   = r_dcache_fsm.read();
    4869             r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
    4870             break;
    4871         }
    4872 
    4873         if ( r_dcache_contains_ptd[way*m_dcache_sets+set] ) // TLB flush
     4859        size_t way = r_dcache_cc_way.read();
     4860        size_t set = r_dcache_cc_set.read();
     4861
     4862        if (r_dcache_in_tlb[way * m_dcache_sets + set])       // selective TLB inval
     4863        {
     4864            r_dcache_in_tlb[way * m_dcache_sets + set] = false;
     4865            r_dcache_tlb_inval_line = r_cc_receive_dcache_nline.read();
     4866            r_dcache_tlb_inval_set  = 0;
     4867            r_dcache_fsm_scan_save  = r_dcache_fsm.read();
     4868            r_dcache_fsm            = DCACHE_INVAL_TLB_SCAN;
     4869            break;
     4870        }
     4871
     4872        if (r_dcache_contains_ptd[way * m_dcache_sets + set]) // TLB flush
    48744873        {
    48754874            r_itlb.reset();
    48764875            r_dtlb.reset();
    4877             r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     4876            r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    48784877
    48794878#if DEBUG_DCACHE
    4880 if ( m_debug_dcache_fsm )
    4881 {
    4882     std::cout << "  <PROC " << name()
    4883               << " DCACHE_CC_INVAL> Flush DTLB & ITLB" << std::endl;
    4884 }
    4885 #endif
    4886         }
    4887 
    4888         assert (not r_dcache_cc_send_req.read() &&
     4879            if (m_debug_dcache_fsm)
     4880            {
     4881                std::cout << "  <PROC " << name()
     4882                          << " DCACHE_CC_INVAL> Flush DTLB & ITLB" << std::endl;
     4883            }
     4884#endif
     4885        }
     4886
     4887        assert(not r_dcache_cc_send_req.read() &&
    48894888                "ERROR in DCACHE_CC_INVAL: the r_dcache_cc_send_req "
    48904889                "must not be set");
    48914890
    48924891        // Switch slot state to ZOMBI and send CLEANUP command
    4893         r_dcache.write_dir( way,
    4894                             set,
    4895                             CACHE_SLOT_STATE_ZOMBI );
     4892        r_dcache.write_dir(way,
     4893                           set,
     4894                           CACHE_SLOT_STATE_ZOMBI);
    48964895
    48974896        // coherence request completed
     
    49044903
    49054904#if DEBUG_DCACHE
    4906 if ( m_debug_dcache_fsm )
    4907 {
    4908     std::cout << "  <PROC " << name()
    4909         << " DCACHE_CC_INVAL> Switch slot to EMPTY state:" << std::dec
    4910         << " / WAY = " << way
    4911         << " / SET = " << set << std::endl;
    4912 }
     4905        if (m_debug_dcache_fsm)
     4906        {
     4907            std::cout << "  <PROC " << name()
     4908                << " DCACHE_CC_INVAL> Switch slot to EMPTY state:" << std::dec
     4909                << " / WAY = " << way
     4910                << " / SET = " << set << std::endl;
     4911        }
    49134912#endif
    49144913        break;
    49154914    }
    49164915    ///////////////////
    4917     case DCACHE_CC_UPDT:        // hit update: write one word per cycle,
    4918                                 // after possible invalidation of copies in TLBs
    4919     {
    4920         size_t word       = r_dcache_cc_word.read();
    4921         size_t way        = r_dcache_cc_way.read();
    4922         size_t set        = r_dcache_cc_set.read();
    4923 
    4924         if ( r_dcache_in_tlb[way*m_dcache_sets+set] )       // selective TLB inval
    4925         {
    4926             r_dcache_in_tlb[way*m_dcache_sets+set] = false;
     4916    case DCACHE_CC_UPDT: // hit update: write one word per cycle,
     4917                         // after possible invalidation of copies in TLBs
     4918    {
     4919        size_t word = r_dcache_cc_word.read();
     4920        size_t way  = r_dcache_cc_way.read();
     4921        size_t set  = r_dcache_cc_set.read();
     4922
     4923        if (r_dcache_in_tlb[way * m_dcache_sets + set])       // selective TLB inval
     4924        {
     4925            r_dcache_in_tlb[way * m_dcache_sets + set] = false;
    49274926            r_dcache_tlb_inval_line = r_cc_receive_dcache_nline.read();
    49284927            r_dcache_tlb_inval_set  = 0;
     
    49334932        }
    49344933
    4935         if ( r_dcache_contains_ptd[way*m_dcache_sets+set] ) // TLB flush
     4934        if (r_dcache_contains_ptd[way * m_dcache_sets + set]) // TLB flush
    49364935        {
    49374936            r_itlb.reset();
    49384937            r_dtlb.reset();
    4939             r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
     4938            r_dcache_contains_ptd[way * m_dcache_sets + set] = false;
    49404939
    49414940#if DEBUG_DCACHE
    4942 if ( m_debug_dcache_fsm )
    4943 {
    4944     std::cout << "  <PROC " << name()
    4945               << " DCACHE_CC_UPDT> Flush DTLB & ITLB" << std::endl;
    4946 }
     4941            if (m_debug_dcache_fsm)
     4942            {
     4943                std::cout << "  <PROC " << name()
     4944                    << " DCACHE_CC_UPDT> Flush DTLB & ITLB" << std::endl;
     4945            }
    49474946#endif
    49484947        }
     
    49524951                "must not be set");
    49534952       
    4954         if ( not r_cc_receive_updt_fifo_be.rok() ) break;
     4953        if (not r_cc_receive_updt_fifo_be.rok()) break;
    49554954
    49564955        if (r_dcache_cc_need_write.read())
     
    49584957       
    49594958#ifdef INSTRUMENTATION
    4960 m_cpt_dcache_data_write++;
    4961 #endif
    4962             r_dcache.write( way,
    4963                             set,
    4964                             word,
    4965                             r_cc_receive_updt_fifo_data.read(),
    4966                             r_cc_receive_updt_fifo_be.read() );
     4959            m_cpt_dcache_data_write++;
     4960#endif
     4961            r_dcache.write(way,
     4962                           set,
     4963                           word,
     4964                           r_cc_receive_updt_fifo_data.read(),
     4965                           r_cc_receive_updt_fifo_be.read());
    49674966
    49684967            r_dcache_cc_word = word + 1;
    49694968
    49704969#if DEBUG_DCACHE
    4971 if ( m_debug_dcache_fsm )
    4972 {
    4973     std::cout << "  <PROC " << name()
    4974               << " DCACHE_CC_UPDT> Write one word" << std::dec
    4975               << " / WAY = " << way
    4976               << " / SET = " << set
    4977               << " / WORD = " << word
    4978               << " / VALUE = " << std::hex << r_cc_receive_updt_fifo_data.read() << std::endl;
    4979 }
    4980 #endif
    4981         }
    4982 
    4983         if ( r_cc_receive_updt_fifo_eop.read() )  // last word
     4970            if (m_debug_dcache_fsm)
     4971            {
     4972                std::cout << "  <PROC " << name()
     4973                    << " DCACHE_CC_UPDT> Write one word" << std::dec
     4974                    << " / WAY = " << way
     4975                    << " / SET = " << set
     4976                    << " / WORD = " << word
     4977                    << " / VALUE = " << std::hex << r_cc_receive_updt_fifo_data.read() << std::endl;
     4978            }
     4979#endif
     4980        }
     4981
     4982        if (r_cc_receive_updt_fifo_eop.read())  // last word
    49844983        {
    49854984            // no need to write in the cache anymore
     
    49944993            r_dcache_cc_send_updt_tab_idx = r_cc_receive_dcache_updt_tab_idx.read();
    49954994            r_dcache_cc_send_type         = CC_TYPE_MULTI_ACK;
    4996 
    49974995            r_dcache_fsm                  = r_dcache_fsm_cc_save.read();
    49984996        }
     
    50045002    }
    50055003    ///////////////////////////
    5006     case DCACHE_INVAL_TLB_SCAN:         // Scan sequencially all sets for both ITLB & DTLB
    5007                                         // It makes assumption: m_itlb_sets == m_dtlb_sets
    5008                                         // All ways are handled in parallel.
    5009                                         // We enter this state when a DCACHE line is modified,
    5010                                         // and there is a copy in itlb or dtlb.
    5011                                         // It can be caused by:
    5012                                         // - a coherence inval or updt transaction,
    5013                                         // - a line inval caused by a cache miss
    5014                                         // - a processor XTN inval request,
    5015                                         // - a WRITE hit,
    5016                                         // - a Dirty bit update
    5017                                         // Input arguments are:
    5018                                         // - r_dcache_tlb_inval_line
    5019                                         // - r_dcache_tlb_inval_set
    5020                                         // - r_dcache_fsm_scan_save
    5021     {
    5022         paddr_t line = r_dcache_tlb_inval_line.read();
    5023         size_t  set = r_dcache_tlb_inval_set.read();
    5024         size_t  way;
    5025         bool    ok;
    5026 
    5027         for ( way = 0 ; way < m_itlb_ways ; way++ )
    5028         {
    5029             ok = r_itlb.inval( line, way, set );
     5004    case DCACHE_INVAL_TLB_SCAN:  // Scan sequencially all sets for both ITLB & DTLB
     5005                                 // It makes assumption: m_itlb_sets == m_dtlb_sets
     5006                                 // All ways are handled in parallel.
     5007                                 // We enter this state when a DCACHE line is modified,
     5008                                 // and there is a copy in itlb or dtlb.
     5009                                 // It can be caused by:
     5010                                 // - a coherence inval or updt transaction,
     5011                                 // - a line inval caused by a cache miss
     5012                                 // - a processor XTN inval request,
     5013                                 // - a WRITE hit,
     5014                                 // - a Dirty bit update
     5015                                 // Input arguments are:
     5016                                 // - r_dcache_tlb_inval_line
     5017                                 // - r_dcache_tlb_inval_set
     5018                                 // - r_dcache_fsm_scan_save
     5019    {
     5020        paddr_t line = r_dcache_tlb_inval_line.read();
     5021        size_t set = r_dcache_tlb_inval_set.read();
     5022        size_t way;
     5023        bool ok;
     5024
     5025        for (way = 0; way < m_itlb_ways; way++)
     5026        {
     5027            ok = r_itlb.inval(line, way, set);
    50305028
    50315029#if DEBUG_DCACHE
    5032 if ( m_debug_dcache_fsm and ok )
    5033 {
    5034     std::cout << "  <PROC " << name()
    5035               << ".DCACHE_INVAL_TLB_SCAN> Invalidate ITLB entry:" << std::hex
    5036               << " line = " << line << std::dec
    5037               << " / set = " << set
    5038               << " / way = " << way << std::endl;
    5039 }
    5040 #endif
    5041         }
    5042 
    5043         for ( way = 0 ; way < m_dtlb_ways ; way++ )
    5044         {
    5045             ok = r_dtlb.inval( line, way, set );
     5030            if (m_debug_dcache_fsm and ok)
     5031            {
     5032                std::cout << "  <PROC " << name()
     5033                    << ".DCACHE_INVAL_TLB_SCAN> Invalidate ITLB entry:" << std::hex
     5034                    << " line = " << line << std::dec
     5035                    << " / set = " << set
     5036                    << " / way = " << way << std::endl;
     5037            }
     5038#endif
     5039        }
     5040
     5041        for (way = 0; way < m_dtlb_ways; way++)
     5042        {
     5043            ok = r_dtlb.inval( line, way, set);
    50465044
    50475045#if DEBUG_DCACHE
    5048 if ( m_debug_dcache_fsm and ok )
    5049 std::cout << "  <PROC " << name() << " DCACHE_INVAL_TLB_SCAN>"
    5050           << " Invalidate DTLB entry" << std::hex
    5051           << " / line = " << line << std::dec
    5052           << " / set = " << set
    5053           << " / way = " << way << std::endl;
     5046            if (m_debug_dcache_fsm and ok)
     5047                std::cout << "  <PROC " << name() << " DCACHE_INVAL_TLB_SCAN>"
     5048                    << " Invalidate DTLB entry" << std::hex
     5049                    << " / line = " << line << std::dec
     5050                    << " / set = " << set
     5051                    << " / way = " << way << std::endl;
    50545052#endif
    50555053        }
    50565054
    50575055        // return to the calling state when TLB inval completed
    5058         if ( r_dcache_tlb_inval_set.read() == (m_dtlb_sets-1) )
     5056        if (r_dcache_tlb_inval_set.read() == (m_dtlb_sets - 1))
    50595057        {
    50605058            r_dcache_fsm = r_dcache_fsm_scan_save.read();
     
    50755073    // The simulation exit if the number of consecutive frozen cycles
    50765074    // is larger than the m_max_frozen_cycles (constructor parameter)
    5077     if ( (m_ireq.valid and not m_irsp.valid) or (m_dreq.valid and not m_drsp.valid) )
    5078     {
    5079         m_cpt_frz_cycles++;             // used for instrumentation
    5080         m_cpt_stop_simulation++;        // used for debug
    5081         if ( m_cpt_stop_simulation > m_max_frozen_cycles )
     5075    if ((m_ireq.valid and not m_irsp.valid) or (m_dreq.valid and not m_drsp.valid))
     5076    {
     5077        m_cpt_frz_cycles++;      // used for instrumentation
     5078        m_cpt_stop_simulation++; // used for debug
     5079        if (m_cpt_stop_simulation > m_max_frozen_cycles)
    50825080        {
    50835081            std::cout << std::dec << "ERROR in CC_VCACHE_WRAPPER " << name() << std::endl
     
    50965094    /////////// execute one iss cycle /////////////////////////////////
    50975095    {
    5098     uint32_t it = 0;
    5099     for (size_t i=0; i<(size_t)iss_t::n_irq; i++) if(p_irq[i].read()) it |= (1<<i);
    5100     r_iss.executeNCycles(1, m_irsp, m_drsp, it);
     5096        uint32_t it = 0;
     5097        for (size_t i = 0; i < (size_t) iss_t::n_irq; i++) if (p_irq[i].read()) it |= (1 << i);
     5098        r_iss.executeNCycles(1, m_irsp, m_drsp, it);
    51015099    }
    51025100
     
    51425140
    51435141
    5144     switch ( r_vci_cmd_fsm.read() )
     5142    switch (r_vci_cmd_fsm.read())
    51455143    {
    51465144        //////////////
     
    51545152            // using the r_vci_cmd_imiss_prio flip-flop.
    51555153
    5156             size_t      wbuf_min;
    5157             size_t      wbuf_max;
     5154            size_t wbuf_min;
     5155            size_t wbuf_max;
    51585156
    51595157            bool dcache_miss_req = r_dcache_vci_miss_req.read() and
    5160                  ( not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read() );
    5161 
    5162             bool dcache_ll_req   = r_dcache_vci_ll_req.read() and
    5163                  ( not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read() );
    5164 
    5165             bool dcache_sc_req   = r_dcache_vci_sc_req.read() and
    5166                  ( not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read() );
    5167 
    5168             bool dcache_cas_req   = r_dcache_vci_cas_req.read() and
    5169                  ( not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read() );
     5158                 (not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read());
     5159
     5160            bool dcache_ll_req = r_dcache_vci_ll_req.read() and
     5161                 (not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read());
     5162
     5163            bool dcache_sc_req = r_dcache_vci_sc_req.read() and
     5164                 (not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read());
     5165
     5166            bool dcache_cas_req = r_dcache_vci_cas_req.read() and
     5167                 (not r_icache_miss_req.read() or not r_vci_cmd_imiss_prio.read());
    51705168
    51715169            bool icache_miss_req = r_icache_miss_req.read() and
    5172                  ( not (r_dcache_vci_miss_req.read() or
    5173                         r_dcache_vci_ll_req.read()   or
    5174                         r_dcache_vci_cas_req.read()  or
    5175                         r_dcache_vci_sc_req.read())
    5176                      or r_vci_cmd_imiss_prio.read() );
     5170                 (not (r_dcache_vci_miss_req.read() or
     5171                       r_dcache_vci_ll_req.read()   or
     5172                       r_dcache_vci_cas_req.read()  or
     5173                       r_dcache_vci_sc_req.read())  or
     5174                       r_vci_cmd_imiss_prio.read());
    51775175
    51785176            // 1 - Data unc write
    5179             if ( r_dcache_vci_unc_req.read() and r_dcache_vci_unc_write.read())
     5177            if (r_dcache_vci_unc_req.read() and r_dcache_vci_unc_write.read())
    51805178            {
    51815179                r_vci_cmd_fsm        = CMD_DATA_UNC_WRITE;
    51825180                r_dcache_vci_unc_req = false;
    5183 //                m_cpt_dunc_transaction++;
    51845181            }
    51855182            // 2 data read miss
    5186             else if ( dcache_miss_req and r_wbuf.miss(r_dcache_vci_paddr.read()) )
     5183            else if (dcache_miss_req and r_wbuf.miss(r_dcache_vci_paddr.read()))
    51875184            {
    51885185                r_vci_cmd_fsm         = CMD_DATA_MISS;
    51895186                r_dcache_vci_miss_req = false;
    51905187                r_vci_cmd_imiss_prio  = true;
    5191 //                m_cpt_dmiss_transaction++;
    51925188            }
    51935189            // 3 - Data Read Uncachable
    5194             else if ( r_dcache_vci_unc_req.read() and not r_dcache_vci_unc_write.read() )
     5190            else if (r_dcache_vci_unc_req.read() and not r_dcache_vci_unc_write.read())
    51955191            {
    51965192                r_vci_cmd_fsm        = CMD_DATA_UNC_READ;
    51975193                r_dcache_vci_unc_req = false;
    5198 //                m_cpt_dunc_transaction++;
    51995194            }
    52005195            // 4 - Data Linked Load
    5201             else if ( dcache_ll_req and r_wbuf.miss(r_dcache_vci_paddr.read()))
     5196            else if (dcache_ll_req and r_wbuf.miss(r_dcache_vci_paddr.read()))
    52025197            {
    52035198                r_vci_cmd_fsm         = CMD_DATA_LL;
    52045199                r_dcache_vci_ll_req   = false;
    52055200                r_vci_cmd_imiss_prio  = true;
    5206 //              m_cpt_ll_transaction++;
    52075201            }
    52085202            // 5 - Instruction Miss
    5209             else if ( icache_miss_req and r_wbuf.miss(r_icache_vci_paddr.read()) )
     5203            else if (icache_miss_req and r_wbuf.miss(r_icache_vci_paddr.read()))
    52105204            {
    52115205                r_vci_cmd_fsm        = CMD_INS_MISS;
    52125206                r_icache_miss_req    = false;
    52135207                r_vci_cmd_imiss_prio = false;
    5214 //                m_cpt_imiss_transaction++;
    52155208            }
    52165209            // 6 - Instruction Uncachable
    5217             else if ( r_icache_unc_req.read() )
    5218             {
    5219                 r_vci_cmd_fsm       = CMD_INS_UNC;
    5220                 r_icache_unc_req    = false;
    5221 //                m_cpt_iunc_transaction++;
     5210            else if (r_icache_unc_req.read())
     5211            {
     5212                r_vci_cmd_fsm    = CMD_INS_UNC;
     5213                r_icache_unc_req = false;
    52225214            }
    52235215            // 7 - Data Write
    5224             else if ( r_wbuf.rok(&wbuf_min, &wbuf_max) )
    5225             {
    5226                 r_vci_cmd_fsm       = CMD_DATA_WRITE;
    5227                 r_vci_cmd_cpt       = wbuf_min;
    5228                 r_vci_cmd_min       = wbuf_min;
    5229                 r_vci_cmd_max       = wbuf_max;
    5230 //                m_cpt_write_transaction++;
    5231 //                m_length_write_transaction += (wbuf_max-wbuf_min+1);
     5216            else if (r_wbuf.rok(&wbuf_min, &wbuf_max))
     5217            {
     5218                r_vci_cmd_fsm = CMD_DATA_WRITE;
     5219                r_vci_cmd_cpt = wbuf_min;
     5220                r_vci_cmd_min = wbuf_min;
     5221                r_vci_cmd_max = wbuf_max;
    52325222            }
    52335223            // 8 - Data Store Conditionnal
    5234             else if ( dcache_sc_req and r_wbuf.miss(r_dcache_vci_paddr.read()) )
    5235             {
    5236                 r_vci_cmd_fsm           = CMD_DATA_SC;
    5237                 r_dcache_vci_sc_req     = false;
    5238                 r_vci_cmd_imiss_prio    = true;
    5239                 r_vci_cmd_cpt           = 0;
    5240 //              m_cpt_sc_transaction++;
     5224            else if (dcache_sc_req and r_wbuf.miss(r_dcache_vci_paddr.read()))
     5225            {
     5226                r_vci_cmd_fsm        = CMD_DATA_SC;
     5227                r_dcache_vci_sc_req  = false;
     5228                r_vci_cmd_imiss_prio = true;
     5229                r_vci_cmd_cpt        = 0;
    52415230            }
    52425231            // 9 - Compare And Swap
    5243             else if ( dcache_cas_req and r_wbuf.miss(r_dcache_vci_paddr.read()) )
    5244             {
    5245                 r_vci_cmd_fsm           = CMD_DATA_CAS;
    5246                 r_dcache_vci_cas_req    = false;
    5247                 r_vci_cmd_imiss_prio    = true;
    5248                 r_vci_cmd_cpt           = 0;
    5249 //              m_cpt_cas_transaction++;
     5232            else if (dcache_cas_req and r_wbuf.miss(r_dcache_vci_paddr.read()))
     5233            {
     5234                r_vci_cmd_fsm        = CMD_DATA_CAS;
     5235                r_dcache_vci_cas_req = false;
     5236                r_vci_cmd_imiss_prio = true;
     5237                r_vci_cmd_cpt        = 0;
    52505238            }
    52515239
    52525240#if DEBUG_CMD
    5253 if ( m_debug_cmd_fsm )
    5254 {
    5255 std::cout << "  <PROC " << name() << " CMD_IDLE>"
    5256           << " / dmiss_req = " << dcache_miss_req
    5257           << " / imiss_req = " << icache_miss_req
    5258           << std::endl;
    5259 }
     5241            if (m_debug_cmd_fsm )
     5242            {
     5243                std::cout << "  <PROC " << name() << " CMD_IDLE>"
     5244                    << " / dmiss_req = " << dcache_miss_req
     5245                    << " / imiss_req = " << icache_miss_req
     5246                    << std::endl;
     5247            }
    52605248#endif
    52615249            break;
     
    52645252        case CMD_DATA_WRITE:
    52655253        {
    5266             if ( p_vci.cmdack.read() )
     5254            if (p_vci.cmdack.read())
    52675255            {
    52685256                r_vci_cmd_cpt = r_vci_cmd_cpt + 1;
    52695257                if (r_vci_cmd_cpt == r_vci_cmd_max) // last flit sent
    52705258                {
    5271                     r_vci_cmd_fsm = CMD_IDLE ;
    5272                     r_wbuf.sent() ;
     5259                    r_vci_cmd_fsm = CMD_IDLE;
     5260                    r_wbuf.sent();
    52735261                }
    52745262            }
     
    52805268        {
    52815269            // The CAS and SC VCI commands contain two flits
    5282             if ( p_vci.cmdack.read() )
     5270            if (p_vci.cmdack.read())
    52835271            {
    52845272               r_vci_cmd_cpt = r_vci_cmd_cpt + 1;
     
    52965284        {
    52975285            // all read VCI commands contain one single flit
    5298             if ( p_vci.cmdack.read() ) {
     5286            if (p_vci.cmdack.read()) {
    52995287                r_vci_cmd_fsm = CMD_IDLE;
    53005288            }
     
    53315319    //////////////////////////////////////////////////////////////////////////
    53325320
    5333     switch ( r_vci_rsp_fsm.read() )
     5321    switch (r_vci_rsp_fsm.read())
    53345322    {
    53355323    //////////////
    53365324    case RSP_IDLE:
    53375325    {
    5338         if ( p_vci.rspval.read() )
     5326        if (p_vci.rspval.read())
    53395327        {
    53405328            r_vci_rsp_cpt = 0;
    53415329
    5342             if      ( (p_vci.rpktid.read() & 0x7) ==  TYPE_DATA_UNC  )
     5330            if ((p_vci.rpktid.read() & 0x7) ==  TYPE_DATA_UNC)
    53435331            {
    53445332                r_vci_rsp_fsm = RSP_DATA_UNC;
    53455333            }
    5346             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_DATA_MISS )
     5334            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_READ_DATA_MISS)
    53475335            {
    53485336                r_vci_rsp_fsm = RSP_DATA_MISS;
    53495337            }
    5350             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_UNC   )
     5338            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_UNC)
    53515339            {
    53525340                r_vci_rsp_fsm = RSP_INS_UNC;
    53535341            }
    5354             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_MISS  )
     5342            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_MISS)
    53555343            {
    53565344                r_vci_rsp_fsm = RSP_INS_MISS;
    53575345            }
    5358             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_WRITE          )
     5346            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_WRITE)
    53595347            {
    53605348                r_vci_rsp_fsm = RSP_DATA_WRITE;
    53615349            }
    5362             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_CAS            )
     5350            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_CAS)
    53635351            {
    53645352                r_vci_rsp_fsm = RSP_DATA_UNC;
    53655353            }
    5366             else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_LL             )
     5354            else if ((p_vci.rpktid.read() & 0x7) ==  TYPE_LL)
    53675355            {
    53685356                r_vci_rsp_fsm = RSP_DATA_LL;
    53695357            }
    5370             else if ( (p_vci.rpktid.read() & 0x7) == TYPE_SC             )
     5358            else if ((p_vci.rpktid.read() & 0x7) == TYPE_SC)
    53715359            {
    53725360                r_vci_rsp_fsm = RSP_DATA_UNC;
     
    53825370        case RSP_INS_MISS:
    53835371        {
    5384             if ( p_vci.rspval.read() )
    5385             {
    5386                 if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
     5372            if (p_vci.rspval.read())
     5373            {
     5374                if ((p_vci.rerror.read() & 0x1) != 0)  // error reported
    53875375                {
    53885376                    r_vci_rsp_ins_error = true;
    5389                     if ( p_vci.reop.read() ) r_vci_rsp_fsm = RSP_IDLE;
     5377                    if (p_vci.reop.read()) r_vci_rsp_fsm = RSP_IDLE;
    53905378                }
    53915379                else                                        // no error reported
    53925380                {
    5393                     if ( r_vci_rsp_fifo_icache.wok() )
     5381                    if (r_vci_rsp_fifo_icache.wok())
    53945382                    {
    5395                         if ( r_vci_rsp_cpt.read() >= m_icache_words )
     5383                        if (r_vci_rsp_cpt.read() >= m_icache_words)
    53965384                        {
    53975385                            std::cout << "ERROR in VCI_CC_VCACHE " << name()
     
    54005388                            exit(0);
    54015389                        }
    5402                         r_vci_rsp_cpt                 = r_vci_rsp_cpt.read() + 1;
    5403                         vci_rsp_fifo_icache_put       = true,
    5404                         vci_rsp_fifo_icache_data      = p_vci.rdata.read();
    5405                         if ( p_vci.reop.read() )
     5390                        r_vci_rsp_cpt            = r_vci_rsp_cpt.read() + 1;
     5391                        vci_rsp_fifo_icache_put  = true,
     5392                        vci_rsp_fifo_icache_data = p_vci.rdata.read();
     5393                        if (p_vci.reop.read())
    54065394                        {
    5407                             if ( r_vci_rsp_cpt.read() != (m_icache_words - 1) )
     5395                            if (r_vci_rsp_cpt.read() != (m_icache_words - 1))
    54085396                            {
    54095397                                std::cout << "ERROR in VCI_CC_VCACHE " << name()
     
    54125400                                exit(0);
    54135401                            }
    5414                             r_vci_rsp_fsm    = RSP_IDLE;
     5402                            r_vci_rsp_fsm = RSP_IDLE;
    54155403                        }
    54165404                    }
     
    54225410        case RSP_INS_UNC:
    54235411        {
    5424             if (p_vci.rspval.read() )
    5425             {
    5426                 assert( p_vci.reop.read() and
     5412            if (p_vci.rspval.read())
     5413            {
     5414                assert(p_vci.reop.read() and
    54275415                "illegal VCI response packet for uncachable instruction");
    54285416
    5429                 if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
     5417                if ((p_vci.rerror.read() & 0x1) != 0)  // error reported
    54305418                {
    54315419                    r_vci_rsp_ins_error = true;
     
    54345422                else                                         // no error reported
    54355423                {
    5436                     if ( r_vci_rsp_fifo_icache.wok())
     5424                    if (r_vci_rsp_fifo_icache.wok())
    54375425                    {
    5438                         vci_rsp_fifo_icache_put       = true;
    5439                         vci_rsp_fifo_icache_data      = p_vci.rdata.read();
     5426                        vci_rsp_fifo_icache_put  = true;
     5427                        vci_rsp_fifo_icache_data = p_vci.rdata.read();
    54405428                        r_vci_rsp_fsm = RSP_IDLE;
    54415429                    }
     
    54475435        case RSP_DATA_MISS:
    54485436        {
    5449             if ( p_vci.rspval.read() )
    5450             {
    5451                 if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
     5437            if (p_vci.rspval.read())
     5438            {
     5439                if ((p_vci.rerror.read() & 0x1) != 0)  // error reported
    54525440                {
    54535441                    r_vci_rsp_data_error = true;
    5454                     if ( p_vci.reop.read() ) r_vci_rsp_fsm = RSP_IDLE;
     5442                    if (p_vci.reop.read()) r_vci_rsp_fsm = RSP_IDLE;
    54555443                }
    54565444                else                                        // no error reported
    54575445                {
    5458                     if ( r_vci_rsp_fifo_dcache.wok() )
     5446                    if (r_vci_rsp_fifo_dcache.wok())
    54595447                    {
    5460                         assert( (r_vci_rsp_cpt.read() < m_dcache_words) and
     5448                        assert((r_vci_rsp_cpt.read() < m_dcache_words) and
    54615449                        "The VCI response packet for data miss is too long");
    54625450
    5463                         r_vci_rsp_cpt                 = r_vci_rsp_cpt.read() + 1;
    5464                         vci_rsp_fifo_dcache_put       = true,
    5465                         vci_rsp_fifo_dcache_data      = p_vci.rdata.read();
    5466                         if ( p_vci.reop.read() )
     5451                        r_vci_rsp_cpt            = r_vci_rsp_cpt.read() + 1;
     5452                        vci_rsp_fifo_dcache_put  = true,
     5453                        vci_rsp_fifo_dcache_data = p_vci.rdata.read();
     5454                        if (p_vci.reop.read())
    54675455                        {
    5468                             assert( (r_vci_rsp_cpt.read() == m_dcache_words - 1) and
     5456                            assert((r_vci_rsp_cpt.read() == m_dcache_words - 1) and
    54695457                            "The VCI response packet for data miss is too short");
    54705458
    5471                             r_vci_rsp_fsm     = RSP_IDLE;
     5459                            r_vci_rsp_fsm = RSP_IDLE;
    54725460                        }
    54735461                    }
     
    54795467        case RSP_DATA_UNC:
    54805468        {
    5481             if (p_vci.rspval.read() )
    5482             {
    5483                 assert( p_vci.reop.read() and
     5469            if (p_vci.rspval.read())
     5470            {
     5471                assert(p_vci.reop.read() and
    54845472                "illegal VCI response packet for uncachable read data");
    54855473
    5486                 if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
     5474                if ((p_vci.rerror.read() & 0x1) != 0)  // error reported
    54875475                {
    54885476                    r_vci_rsp_data_error = true;
    54895477                    r_vci_rsp_fsm = RSP_IDLE;
    54905478                }
    5491                 else                                         // no error reported
     5479                else // no error reported
    54925480                {
    5493                     if ( r_vci_rsp_fifo_dcache.wok())
     5481                    if (r_vci_rsp_fifo_dcache.wok())
    54945482                    {
    5495                         vci_rsp_fifo_dcache_put       = true;
    5496                         vci_rsp_fifo_dcache_data      = p_vci.rdata.read();
     5483                        vci_rsp_fifo_dcache_put = true;
     5484                        vci_rsp_fifo_dcache_data = p_vci.rdata.read();
    54975485                        r_vci_rsp_fsm = RSP_IDLE;
    54985486                    }
     
    55045492        case RSP_DATA_LL:
    55055493        {
    5506             if ( p_vci.rspval.read() )
    5507             {
    5508                 if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
     5494            if (p_vci.rspval.read())
     5495            {
     5496                if ((p_vci.rerror.read() & 0x1) != 0)  // error reported
    55095497                {
    55105498                    r_vci_rsp_data_error = true;
     
    55145502                if (r_vci_rsp_cpt.read() == 0) //first flit
    55155503                {
    5516                     if(r_vci_rsp_fifo_dcache.wok())
     5504                    if (r_vci_rsp_fifo_dcache.wok())
    55175505                    {
    55185506                        assert(!p_vci.reop.read() &&
     
    55265514                else // last flit
    55275515                {
    5528                     if(r_vci_rsp_fifo_dcache.wok())
     5516                    if (r_vci_rsp_fifo_dcache.wok())
    55295517                    {
    55305518                        assert(p_vci.reop.read() &&
     
    55445532            if (p_vci.rspval.read())
    55455533            {
    5546                 assert( p_vci.reop.read() and
     5534                assert(p_vci.reop.read() and
    55475535                "a VCI response packet must contain one flit for a write transaction");
    55485536
    55495537                r_vci_rsp_fsm = RSP_IDLE;
    5550                 uint32_t   wbuf_index = p_vci.rtrdid.read();
     5538                uint32_t wbuf_index = p_vci.rtrdid.read();
    55515539                r_wbuf.completed(wbuf_index);
    5552                 if ( (p_vci.rerror.read()&0x1) != 0 ) r_iss.setWriteBerr();
     5540                if ((p_vci.rerror.read() & 0x1) != 0) r_iss.setWriteBerr();
    55535541            }
    55545542            break;
     
    55635551    // soon as the request has been sent.
    55645552    /////////////////////////////////////////////////////////////////////////////////////
    5565     switch ( r_cc_send_fsm.read() )
     5553    switch (r_cc_send_fsm.read())
    55665554    {
    55675555        ///////////////////////////
     
    55755563            ///////////////////////////////////////////////////////
    55765564            bool update_last_client = r_cc_send_last_client.read();
    5577             if ( r_cc_send_last_client.read() == 0 ) // last client was dcache
     5565            if (r_cc_send_last_client.read() == 0) // last client was dcache
    55785566            {
    55795567                if (r_icache_cc_send_req.read()) // request from icache
     
    55915579            {
    55925580                // the new client is dcache and has a cleanup request
    5593                 if      ( (update_last_client == 0) and
     5581                if ((update_last_client == 0) and
    55945582                          (r_dcache_cc_send_type.read() == CC_TYPE_CLEANUP))
    55955583                    r_cc_send_fsm = CC_SEND_CLEANUP_1;
    55965584                // the new client is dcache and has a multi acknowledgement request
    5597                 else if ( (update_last_client == 0) and
     5585                else if ((update_last_client == 0) and
    55985586                          (r_dcache_cc_send_type.read() == CC_TYPE_MULTI_ACK))
    55995587                    r_cc_send_fsm = CC_SEND_MULTI_ACK;
    56005588                // the new client is icache and has a cleanup request
    5601                 else if ( (update_last_client == 1) and
     5589                else if ((update_last_client == 1) and
    56025590                          (r_icache_cc_send_type.read() == CC_TYPE_CLEANUP))
    56035591                    r_cc_send_fsm = CC_SEND_CLEANUP_1;
    56045592                // the new client is icache and has a multi acknowledgement request
    5605                 else if ( (update_last_client == 1) and
     5593                else if ((update_last_client == 1) and
    56065594                        (r_icache_cc_send_type.read() == CC_TYPE_MULTI_ACK))
    56075595                    r_cc_send_fsm = CC_SEND_MULTI_ACK;
     
    56385626        {
    56395627            // wait for the flit to be consumed
    5640             if(p_dspin_p2m.read.read())
    5641             {
    5642                 if(r_cc_send_last_client.read() == 0) // dcache active request
     5628            if (p_dspin_p2m.read.read())
     5629            {
     5630                if (r_cc_send_last_client.read() == 0) // dcache active request
    56435631                    r_dcache_cc_send_req = false; // reset dcache request
    56445632                else // icache active request
     
    56615649    // - CC_BROADCAST  : Broadcast invalidate request (both DCACHE & ICACHE)
    56625650    //////////////////////////////////////////////////////////////////////////////
    5663     switch( r_cc_receive_fsm.read() )
     5651    switch (r_cc_receive_fsm.read())
    56645652    {
    56655653        /////////////////////
     
    57225710                // request dcache to handle the BROADCAST
    57235711                r_cc_receive_dcache_req = true;
    5724                 r_cc_receive_dcache_nline  = DspinDhccpParam::dspin_get(receive_data,
     5712                r_cc_receive_dcache_nline = DspinDhccpParam::dspin_get(receive_data,
    57255713                                             DspinDhccpParam::BROADCAST_NLINE);
    57265714                r_cc_receive_dcache_type = CC_TYPE_INVAL;
    57275715                // request icache to handle the BROADCAST
    57285716                r_cc_receive_icache_req = true;
    5729                 r_cc_receive_icache_nline  = DspinDhccpParam::dspin_get(receive_data,
     5717                r_cc_receive_icache_nline = DspinDhccpParam::dspin_get(receive_data,
    57305718                                             DspinDhccpParam::BROADCAST_NLINE);
    57315719                r_cc_receive_icache_type = CC_TYPE_INVAL;
     
    57585746            // for data INVAL, wait for dcache to take the request
    57595747            if (p_dspin_m2p.write.read()           and
    5760                 not r_cc_receive_dcache_req.read() )
     5748                not r_cc_receive_dcache_req.read())
    57615749            {
    57625750                // request dcache to handle the INVAL
     
    57775765            // for ins INVAL, wait for icache to take the request
    57785766            if (p_dspin_m2p.write.read()           and
    5779                 not r_cc_receive_icache_req.read() )
     5767                not r_cc_receive_icache_req.read())
    57805768            {
    57815769                // request icache to handle the INVAL
     
    57985786            if (not r_cc_receive_dcache_req.read())
    57995787            {
    5800                 r_cc_receive_dcache_updt_tab_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_UPDT_INDEX);
     5788                r_cc_receive_dcache_updt_tab_idx = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_UPDT_INDEX);
    58015789                r_cc_receive_fsm = CC_RECEIVE_DATA_UPDT_NLINE;
    58025790                break;
     
    58135801            if (not r_cc_receive_icache_req.read())
    58145802            {
    5815                 r_cc_receive_icache_updt_tab_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_UPDT_INDEX);
     5803                r_cc_receive_icache_updt_tab_idx = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_UPDT_INDEX);
    58165804                r_cc_receive_fsm = CC_RECEIVE_INS_UPDT_NLINE;
    58175805                break;
     
    58275815            // for data INVAL, wait for dcache to take the request and fifo to
    58285816            // be empty
    5829             if ( r_cc_receive_updt_fifo_be.empty() and
    5830                  p_dspin_m2p.write.read() )
    5831             {
    5832                 r_cc_receive_dcache_req = true;
    5833                 r_cc_receive_dcache_nline  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
    5834                 r_cc_receive_word_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
    5835                 r_cc_receive_dcache_type = CC_TYPE_UPDT;
     5817            if (r_cc_receive_updt_fifo_be.empty() and
     5818                 p_dspin_m2p.write.read())
     5819            {
     5820                r_cc_receive_dcache_req   = true;
     5821                r_cc_receive_dcache_nline = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
     5822                r_cc_receive_word_idx     = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
     5823                r_cc_receive_dcache_type  = CC_TYPE_UPDT;
    58365824                // get back to idle state
    58375825                r_cc_receive_fsm = CC_RECEIVE_DATA_UPDT_DATA;
     
    58475835            // for ins INVAL, wait for icache to take the request and fifo to be
    58485836            // empty
    5849             if ( r_cc_receive_updt_fifo_be.empty() and
    5850                  p_dspin_m2p.write.read() )
    5851             {
    5852                 r_cc_receive_icache_req = true;
    5853                 r_cc_receive_icache_nline  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
    5854                 r_cc_receive_word_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
    5855                 r_cc_receive_icache_type = CC_TYPE_UPDT;
     5837            if (r_cc_receive_updt_fifo_be.empty() and
     5838                 p_dspin_m2p.write.read())
     5839            {
     5840                r_cc_receive_icache_req   = true;
     5841                r_cc_receive_icache_nline = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
     5842                r_cc_receive_word_idx     = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
     5843                r_cc_receive_icache_type  = CC_TYPE_UPDT;
    58565844                // get back to idle state
    58575845                r_cc_receive_fsm = CC_RECEIVE_INS_UPDT_DATA;
     
    58725860                cc_receive_updt_fifo_eop  = receive_eop;
    58735861                cc_receive_updt_fifo_put  = true;
    5874                 if ( receive_eop ) r_cc_receive_fsm = CC_RECEIVE_IDLE;
     5862                if (receive_eop ) r_cc_receive_fsm = CC_RECEIVE_IDLE;
    58755863            }
    58765864            break;
     
    58885876                cc_receive_updt_fifo_eop  = receive_eop;
    58895877                cc_receive_updt_fifo_put  = true;
    5890                 if ( receive_eop ) r_cc_receive_fsm = CC_RECEIVE_IDLE;
     5878                if (receive_eop ) r_cc_receive_fsm = CC_RECEIVE_IDLE;
    58915879            }
    58925880            break;
     
    59005888                                                     DspinDhccpParam::CLACK_TYPE);
    59015889
    5902     size_t clack_way  = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
     5890    size_t clack_way = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
    59035891                                                   DspinDhccpParam::CLACK_WAY);
    59045892
    5905     size_t clack_set  = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
     5893    size_t clack_set = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
    59065894                                                   DspinDhccpParam::CLACK_SET);
    59075895
    5908     bool dspin_clack_get      = false;
     5896    bool dspin_clack_get = false;
    59095897    bool dcache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_DATA);
    59105898    bool icache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_INST);
     
    59135901    {
    59145902        // CLACK DATA: Send request to DCACHE FSM
    5915         if (dcache_clack_request and not r_dcache_clack_req.read()){
     5903        if (dcache_clack_request and not r_dcache_clack_req.read())
     5904        {
    59165905            r_dcache_clack_req = true;
    5917             r_dcache_clack_way = clack_way & ((1ULL<<(uint32_log2(m_dcache_ways)))-1);
    5918             r_dcache_clack_set = clack_set & ((1ULL<<(uint32_log2(m_dcache_sets)))-1);
     5906            r_dcache_clack_way = clack_way & ((1ULL << (uint32_log2(m_dcache_ways))) - 1);
     5907            r_dcache_clack_set = clack_set & ((1ULL << (uint32_log2(m_dcache_sets))) - 1);
    59195908            dspin_clack_get    = true;
    59205909        }
    59215910
    59225911        // CLACK INST: Send request to ICACHE FSM
    5923         else if (icache_clack_request and not r_icache_clack_req.read()){
     5912        else if (icache_clack_request and not r_icache_clack_req.read())
     5913        {
    59245914            r_icache_clack_req = true;
    59255915            r_icache_clack_way = clack_way & ((1ULL<<(uint32_log2(m_dcache_ways)))-1);
     
    59715961
    59725962    bool is_sc_or_cas  = (r_vci_cmd_fsm.read() == CMD_DATA_CAS) or
    5973                          (r_vci_cmd_fsm.read() == CMD_DATA_SC );
     5963                         (r_vci_cmd_fsm.read() == CMD_DATA_SC);
    59745964
    59755965    p_vci.pktid  = 0;
     
    59815971    p_vci.cfixed = false;
    59825972
    5983     if ( m_monitor_ok ) {
    5984         if ( p_vci.cmdack.read() == true and p_vci.cmdval == true) {
     5973    if (m_monitor_ok) {
     5974        if (p_vci.cmdack.read() == true and p_vci.cmdval == true) {
    59855975            if (((p_vci.address.read()) >= m_monitor_base) and
    5986                 ((p_vci.address.read()) < m_monitor_base + m_monitor_length) ) {
     5976                ((p_vci.address.read()) < m_monitor_base + m_monitor_length)) {
    59875977                std::cout << "CC_VCACHE Monitor " << name() << std::hex
    59885978                          << " Access type = " << vci_cmd_type_str[p_vci.cmd.read()]
     
    59905980                          << " : address = " << p_vci.address.read()
    59915981                          << " / be = " << p_vci.be.read();
    5992                 if ( p_vci.cmd.read() == vci_param::CMD_WRITE ) {
     5982                if (p_vci.cmd.read() == vci_param::CMD_WRITE ) {
    59935983                    std::cout << " / data = " << p_vci.wdata.read();
    59945984                }
     
    59985988    }
    59995989
    6000     switch ( r_vci_cmd_fsm.read() ) {
     5990    switch (r_vci_cmd_fsm.read()) {
    60015991
    60025992    case CMD_IDLE:
     
    60996089        p_vci.cmdval  = true;
    61006090        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
    6101         if ( r_vci_cmd_cpt.read() == 0 ) p_vci.wdata = r_dcache_llsc_key.read();
    6102         else                             p_vci.wdata = r_dcache_vci_sc_data.read();
     6091        if (r_vci_cmd_cpt.read() == 0) p_vci.wdata = r_dcache_llsc_key.read();
     6092        else                           p_vci.wdata = r_dcache_vci_sc_data.read();
    61036093        p_vci.be      = 0xF;
    61046094        p_vci.trdid   = 0;
     
    61126102        p_vci.cmdval  = true;
    61136103        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
    6114         if ( r_vci_cmd_cpt.read() == 0 ) p_vci.wdata = r_dcache_vci_cas_old.read();
    6115         else                             p_vci.wdata = r_dcache_vci_cas_new.read();
     6104        if (r_vci_cmd_cpt.read() == 0) p_vci.wdata = r_dcache_vci_cas_old.read();
     6105        else                           p_vci.wdata = r_dcache_vci_cas_new.read();
    61166106        p_vci.be      = 0xF;
    61176107        p_vci.trdid   = 0;
     
    61266116    // it depends on the VCI_RSP FSM
    61276117
    6128     switch (r_vci_rsp_fsm.read() )
     6118    switch (r_vci_rsp_fsm.read())
    61296119    {
    61306120        case RSP_DATA_WRITE : p_vci.rspack = true; break;
     
    61426132
    61436133    uint64_t dspin_send_data = 0;
    6144     switch ( r_cc_send_fsm.read() )
     6134    switch (r_cc_send_fsm.read())
    61456135    {
    61466136        //////////////////
     
    61546144        {
    61556145            // initialize dspin send data
    6156 //            DspinDhccpParam::dspin_set(dspin_send_data,
    6157 //                                       0,
    6158 //                                       DspinDhccpParam::P2M_EOP);
    61596146            DspinDhccpParam::dspin_set(dspin_send_data,
    61606147                                       m_cc_global_id,
     
    61646151                                       DspinDhccpParam::P2M_BC);
    61656152
    6166             if(r_cc_send_last_client.read() == 0) // dcache active request
     6153            if (r_cc_send_last_client.read() == 0) // dcache active request
    61676154            {
    61686155                uint64_t dest = (uint64_t) r_dcache_cc_send_nline.read()
     
    61976184
    61986185                DspinDhccpParam::dspin_set(dspin_send_data,
    6199                                            (r_icache_cc_send_nline.read() & 0x300000000ULL)>>32,
     6186                                           (r_icache_cc_send_nline.read() & 0x300000000ULL) >> 32,
    62006187                                           DspinDhccpParam::CLEANUP_NLINE_MSB);
    62016188
     
    62186205        {
    62196206            // initialize dspin send data
    6220 //            DspinDhccpParam::dspin_set(dspin_send_data,
    6221 //                                       1,
    6222 //                                       DspinDhccpParam::P2M_EOP);
    6223 
    6224             if(r_cc_send_last_client.read() == 0) // dcache active request
     6207
     6208            if (r_cc_send_last_client.read() == 0) // dcache active request
    62256209            {
    62266210                DspinDhccpParam::dspin_set(dspin_send_data,
     
    62446228        {
    62456229            // initialize dspin send data
    6246 //            DspinDhccpParam::dspin_set(dspin_send_data,
    6247 //                                       1,
    6248 //                                       DspinDhccpParam::P2M_EOP);
    62496230            DspinDhccpParam::dspin_set(dspin_send_data,
    62506231                                       0,
     
    62546235                                       DspinDhccpParam::P2M_TYPE);
    62556236
    6256             if(r_cc_send_last_client.read() == 0) // dcache active request
     6237            if (r_cc_send_last_client.read() == 0) // dcache active request
    62576238            {
    62586239                uint64_t dest = (uint64_t) r_dcache_cc_send_nline.read()
     
    62946275    // Receive coherence packets
    62956276    // It depends on the CC_RECEIVE FSM
    6296     switch( r_cc_receive_fsm.read() )
     6277    switch (r_cc_receive_fsm.read())
    62976278    {
    62986279        /////////////////////
     
    63506331        case CC_RECEIVE_INS_UPDT_HEADER:
    63516332        {
    6352             if ( not r_cc_receive_icache_req.read())
     6333            if (not r_cc_receive_icache_req.read())
    63536334                p_dspin_m2p.read = true;
    63546335            else
     
    63606341        case CC_RECEIVE_INS_UPDT_NLINE:
    63616342        {
    6362             if(r_cc_receive_updt_fifo_be.empty())
     6343            if (r_cc_receive_updt_fifo_be.empty())
    63636344                p_dspin_m2p.read = true;
    63646345            else
     
    63826363                                                DspinDhccpParam::CLACK_TYPE);
    63836364
    6384     bool dspin_clack_get      = false;
     6365    bool dspin_clack_get = false;
    63856366    bool dcache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_DATA);
    63866367    bool icache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_INST);
     
    64116392// This version of monitor print both Read and Write request
    64126393{
    6413     m_monitor_ok        = true;
    6414     m_monitor_base      = base;
    6415     m_monitor_length    = length;
     6394    m_monitor_ok     = true;
     6395    m_monitor_base   = base;
     6396    m_monitor_length = length;
    64166397}
    64176398
    64186399tmpl(void)::stop_monitor()
    64196400{
    6420     m_monitor_ok        = false;
     6401    m_monitor_ok = false;
    64216402}
    64226403
Note: See TracChangeset for help on using the changeset viewer.