Index: trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp
===================================================================
--- trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp	(revision 107)
+++ trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp	(revision 134)
@@ -1,27 +1,171 @@
-
 #include <systemc>
 #include <sys/time.h>
 #include <iostream>
+#include <sstream>
 #include <cstdlib>
 #include <cstdarg>
+#include <stdint.h>
+#include <fstream>
 
 #include "mapping_table.h"
 #include "mips32.h"
+#include "vci_simhelper.h"
 #include "vci_simple_ram.h"
 #include "vci_multi_tty.h"
+#include "vci_xicu.h"
 #include "vci_simple_ring_network_2.h"
 #include "vci_vgmn.h"
 #include "vci_mem_cache_v4.h"
 #include "vci_cc_xcache_wrapper_v4.h"
-#include "vci_logger.h"
+#include "alloc_elems.h"
 
 #include "iss/gdbserver.h"
 
-//#define  VCI_LOGGER
 #include "segmentation.h"
-#define USE_VGMN
+
+//===========================================
+// Define before include
+//===========================================
+
+// Parameters
+// * Platforms
+#  define PARAM_VCI                         4,8,32,1,1,1,8,4,4,1
+
+#  define USE_OLD_XCACHE                    1
+#  define USE_VGMN                          1
+#  define NB_PROC_MIN                       1
+#  define NB_PROC_MAX                       15
+//                                          min_latency, fifo_depth
+#  define PARAM_VGMN_P                      1          , 8
+#  define PARAM_VGMN_C                      1          , 8
+#  define PARAM_VGMN_X                      2          , 8
+//                                          wrapper_fifo_depth
+#  define PARAM_RING_P                      2
+#  define PARAM_RING_C                      2
+#  define PARAM_RING_X                      2
+//                                          pti    , hwi    , wti, irq
+#  define PARAM_XICU                        nb_proc, nb_proc, 0  , nb_proc
+
+// * Debug
+#  define DEBUG_TOP                         0
+#  define SOCVIEW                           0
+#  define STOP_SIMULATION_NB_FRZ_CYCLES     100000
+                                            
+// * Simulation                             
+#  define FILE_DEFAULT                      "configuration/default.cfg"
+#  define NCYCLES_DEFAULT                   0
+#  define SOFT_DEFAULT                      "soft/bin.soft"
+//===========================================
+
+void usage (char * funcname)
+{
+  std::cout << funcname << " [nb_cycle [file [soft]]] " << std::endl;
+  std::cout << " * nb_cycle : number of simulated cycle, if 0 then no stop condition. (default : " << NCYCLES_DEFAULT << " cycle(s))" << endl;
+  std::cout << " * file     : Configuration file : nb_proc, iways, isets, iwords, dways, dsets, dwords, wnwords, wnlines, wtimeout, memc_nways, memc_nsets, memc_words, memc_heap_size. (default : " << FILE_DEFAULT << " cycle(s))" << endl;
+  std::cout << " * soft     : software executed by this platforms. (default : \"" << SOFT_DEFAULT << "\")" << endl;
+
+  exit(1);
+}
 
 int _main(int argc, char *argv[])
 {
+        if ((argc < 1) or (argc > 4))
+          {
+            std::cout << "Invalid parameters number." << std::endl;
+            usage(argv[0]);
+          }
+
+#if not SOCVIEW
+	int  ncycles = 0;
+
+	if (argc >= 2)
+          ncycles = std::atoi(argv[1]);
+        else
+          ncycles = NCYCLES_DEFAULT;
+
+        if (ncycles == 0)
+          ncycles = -1;
+#endif
+
+        uint32_t nb_proc;
+        uint32_t iways, isets, iwords;
+        uint32_t dways, dsets, dwords;
+        uint32_t wnwords, wnlines, wtimeout;
+        uint32_t memc_nways, memc_nsets, memc_words, memc_heap_size;
+
+        std::ifstream inFile;
+        const char * filename = (argc>=3)?argv[2]:FILE_DEFAULT;
+
+        inFile.open(filename);
+        
+        if (!inFile) 
+          {
+            std::cout << "Can't open file : \"" << filename << "\"." << std::endl;
+            usage(argv[0]);
+          }
+
+        std::string str;
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        nb_proc         =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        iways           =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        isets           =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        iwords          =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        dways           =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        dsets           =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        dwords          =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        wnwords         =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        wnlines         =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        wtimeout        =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        memc_nways      =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        memc_nsets      =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        memc_words      =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        memc_heap_size  =std::atoi(str.c_str());
+
+        if ((nb_proc<NB_PROC_MIN) or
+            (nb_proc>NB_PROC_MAX))
+          {
+            std::cout << "Parameters nb_proc is out of bound." << std::endl;
+            usage(argv[0]);
+          }
+
+        char * soft;
+
+        if (argc >= 4)
+          soft = argv[3];
+        else
+          soft = SOFT_DEFAULT;
+
+        std::cout << "  * Parameters : " << std::endl;
+        std::cout << "    * nb_proc          : " << nb_proc          << std::endl;
+        std::cout << "    * iways            : " << iways            << std::endl;
+        std::cout << "    * isets            : " << isets            << std::endl;
+        std::cout << "    * iwords           : " << iwords           << std::endl;
+        std::cout << "    * dways            : " << dways            << std::endl;
+        std::cout << "    * dsets            : " << dsets            << std::endl;
+        std::cout << "    * dwords           : " << dwords           << std::endl;
+        std::cout << "    * wnwords          : " << wnwords          << std::endl;
+        std::cout << "    * wnlines          : " << wnlines          << std::endl;
+        std::cout << "    * wtimeout         : " << wtimeout         << std::endl;
+        std::cout << "    * memc_nways       : " << memc_nways       << std::endl;
+        std::cout << "    * memc_nsets       : " << memc_nsets       << std::endl;
+        std::cout << "    * memc_words       : " << memc_words       << std::endl;
+        std::cout << "    * memc_heap_size   : " << memc_heap_size   << std::endl;
+        std::cout << "  * Simulation : " << std::endl;
+        std::cout << "    * ncycles          : " << ncycles          << std::endl;
+        std::cout << "    * soft             : " << soft             << std::endl;
+
 	using namespace sc_core;
 	// Avoid repeating these everywhere
@@ -30,31 +174,36 @@
 
 	// Define VCI parameters
-	typedef soclib::caba::VciParams<4,8,32,1,1,1,8,4,4,1> vci_param;
+	typedef soclib::caba::VciParams<PARAM_VCI> vci_param;
 	typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
 	// Mapping table
 
-	soclib::common::MappingTable maptabp(32, IntTab(8), IntTab(8), 0x00300000);
-
-	maptabp.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(2), true));
-	maptabp.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(2), true));
-	maptabp.add(Segment("text" , TEXT_BASE , TEXT_SIZE , IntTab(2), true));
-	maptabp.add(Segment("tty"  , TTY_BASE  , TTY_SIZE  , IntTab(1), false));
-	maptabp.add(Segment("mc_r" , MC_R_BASE , MC_R_SIZE , IntTab(2), false, true, IntTab(0)));
-	maptabp.add(Segment("mc_m" , MC_M_BASE , MC_M_SIZE , IntTab(2), true ));
-	maptabp.add(Segment("ptba" , PTD_ADDR , TAB_SIZE   , IntTab(2), true));
+	soclib::common::MappingTable maptabp(32, IntTab(8), IntTab(8), 0x00300000); // size, level_addr_bits, level_id_bits, cacheability_mask
+
+	maptabp.add(Segment("reset"    , RESET_BASE    , RESET_SIZE    , IntTab(2), true));
+	maptabp.add(Segment("excep"    , EXCEP_BASE    , EXCEP_SIZE    , IntTab(2), true));
+
+	maptabp.add(Segment("tty"      , TTY_BASE      , TTY_SIZE      , IntTab(1), false));
+	maptabp.add(Segment("text"     , TEXT_BASE     , TEXT_SIZE     , IntTab(2), true));
+	maptabp.add(Segment("mc_r"     , MC_R_BASE     , MC_R_SIZE     , IntTab(2), false, true, IntTab(0)));
+	maptabp.add(Segment("mc_m"     , MC_M_BASE     , MC_M_SIZE     , IntTab(2), true));
+	// maptabp.add(Segment("ptba"     , PTD_ADDR      , TAB_SIZE      , IntTab(2), true));
+	maptabp.add(Segment("xicu"     , XICU_BASE     , XICU_SIZE     , IntTab(3), false));
+	maptabp.add(Segment("simhelper", SIMHELPER_BASE, SIMHELPER_SIZE, IntTab(4), false));
  
 	std::cout << maptabp << std::endl;
 
         soclib::common::MappingTable maptabc(32, IntTab(8), IntTab(8), 0x00300000);
-	maptabc.add(Segment("c_proc0" , C_PROC0_BASE , C_PROC0_SIZE , IntTab(0), false, true, IntTab(0)));
-	maptabc.add(Segment("c_proc1" , C_PROC1_BASE , C_PROC1_SIZE , IntTab(1), false, true, IntTab(1)));
-	maptabc.add(Segment("c_proc2" , C_PROC2_BASE , C_PROC2_SIZE , IntTab(2), false, true, IntTab(2)));
-	maptabc.add(Segment("c_proc3" , C_PROC3_BASE , C_PROC3_SIZE , IntTab(3), false, true, IntTab(3)));
-	maptabc.add(Segment("mc_r"    , MC_R_BASE , MC_R_SIZE , IntTab(4), false, false));
-	maptabc.add(Segment("mc_m"  , MC_M_BASE , MC_M_SIZE  , IntTab(4), false, false));
-	maptabc.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(4), false, false));
-	maptabc.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(4), false, false));
-	maptabc.add(Segment("text" , TEXT_BASE , TEXT_SIZE , IntTab(4), false, false));
-	maptabc.add(Segment("ptba" , PTD_ADDR  , TAB_SIZE  , IntTab(4), false, false));
+        for (uint32_t i=0; i<nb_proc; ++i)
+        {
+          std::ostringstream str;
+          str << "c_proc_" << i;
+          maptabc.add(Segment(str.str().c_str(), C_PROC_BASE+i*C_PROC_SPAN, C_PROC_SIZE , IntTab(i), false, true, IntTab(i)));
+        }
+	maptabc.add(Segment("mc_r"    , MC_R_BASE  , MC_R_SIZE   , IntTab(nb_proc), false, false));
+	maptabc.add(Segment("mc_m"    , MC_M_BASE  , MC_M_SIZE   , IntTab(nb_proc), false, false));
+	maptabc.add(Segment("reset"   , RESET_BASE , RESET_SIZE  , IntTab(nb_proc), false, false));
+	maptabc.add(Segment("excep"   , EXCEP_BASE , EXCEP_SIZE  , IntTab(nb_proc), false, false));
+	maptabc.add(Segment("text"    , TEXT_BASE  , TEXT_SIZE   , IntTab(nb_proc), false, false));
+	// maptabc.add(Segment("ptba"    , PTD_ADDR   , TAB_SIZE    , IntTab(nb_proc), false, false));
 
 	std::cout << maptabc << std::endl;
@@ -65,5 +214,5 @@
 	maptabx.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(0), false));
 	maptabx.add(Segment("text" , TEXT_BASE , TEXT_SIZE , IntTab(0), false));
-	maptabx.add(Segment("ptba" , PTD_ADDR  , TAB_SIZE  , IntTab(0), false));
+	// maptabx.add(Segment("ptba" , PTD_ADDR  , TAB_SIZE  , IntTab(0), false));
 	
 	std::cout << maptabx << std::endl;
@@ -73,57 +222,19 @@
 	sc_signal<bool> signal_resetn("resetn");
    
-	sc_signal<bool> signal_proc0_it0("proc0_it0"); 
-	sc_signal<bool> signal_proc0_it1("proc0_it1"); 
-	sc_signal<bool> signal_proc0_it2("proc0_it2"); 
-	sc_signal<bool> signal_proc0_it3("proc0_it3"); 
-	sc_signal<bool> signal_proc0_it4("proc0_it4"); 
-	sc_signal<bool> signal_proc0_it5("proc0_it5");
-
-	sc_signal<bool> signal_proc1_it0("proc1_it0"); 
-	sc_signal<bool> signal_proc1_it1("proc1_it1"); 
-	sc_signal<bool> signal_proc1_it2("proc1_it2"); 
-	sc_signal<bool> signal_proc1_it3("proc1_it3"); 
-	sc_signal<bool> signal_proc1_it4("proc1_it4"); 
-	sc_signal<bool> signal_proc1_it5("proc1_it5");
-
-	sc_signal<bool> signal_proc2_it0("proc2_it0"); 
-	sc_signal<bool> signal_proc2_it1("proc2_it1"); 
-	sc_signal<bool> signal_proc2_it2("proc2_it2"); 
-	sc_signal<bool> signal_proc2_it3("proc2_it3"); 
-	sc_signal<bool> signal_proc2_it4("proc2_it4"); 
-	sc_signal<bool> signal_proc2_it5("proc2_it5");
-
-	sc_signal<bool> signal_proc3_it0("proc3_it0"); 
-	sc_signal<bool> signal_proc3_it1("proc3_it1"); 
-	sc_signal<bool> signal_proc3_it2("proc3_it2"); 
-	sc_signal<bool> signal_proc3_it3("proc3_it3"); 
-	sc_signal<bool> signal_proc3_it4("proc3_it4"); 
-	sc_signal<bool> signal_proc3_it5("proc3_it5");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_rw_proc0("vci_ini_rw_proc0");
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_c_proc0("vci_ini_c_proc0");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_tgt_proc0("vci_tgt_proc0");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_rw_proc1("vci_ini_rw_proc1");
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_c_proc1("vci_ini_c_proc1");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_tgt_proc1("vci_tgt_proc1");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_rw_proc2("vci_ini_rw_proc2");
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_c_proc2("vci_ini_c_proc2");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_tgt_proc2("vci_tgt_proc2");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_rw_proc3("vci_ini_rw_proc3");
-	soclib::caba::VciSignals<vci_param> signal_vci_ini_c_proc3("vci_ini_c_proc3");
-
-	soclib::caba::VciSignals<vci_param> signal_vci_tgt_proc3("vci_tgt_proc3");
+	sc_signal<bool> ** signal_proc_it = soclib::common::alloc_elems<sc_signal<bool> >("proc_it", nb_proc, 6);
+
+	soclib::caba::VciSignals<vci_param> * signal_vci_ini_rw_proc = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_ini_rw_proc", nb_proc);
+	soclib::caba::VciSignals<vci_param> * signal_vci_ini_c_proc  = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_ini_c_proc" , nb_proc);
+	soclib::caba::VciSignals<vci_param> * signal_vci_tgt_proc    = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("vci_tgt_proc"   , nb_proc);
 
 	soclib::caba::VciSignals<vci_param> signal_vci_tgt_tty("vci_tgt_tty");
 
+	soclib::caba::VciSignals<vci_param> signal_vci_tgt_simhelper("signal_vci_tgt_simhelper");
+
 	soclib::caba::VciSignals<vci_param> signal_vci_tgt_rom("vci_tgt_rom");
 
 	soclib::caba::VciSignals<vci_param> signal_vci_tgt_xram("vci_tgt_xram");
+
+	soclib::caba::VciSignals<vci_param> signal_vci_tgt_xicu("vci_tgt_xicu");
 
 	soclib::caba::VciSignals<vci_param> signal_vci_ixr_memc("vci_ixr_memc");
@@ -132,126 +243,103 @@
 	soclib::caba::VciSignals<vci_param> signal_vci_tgt_cleanup_memc("vci_tgt_cleanup_memc");
 
-	sc_signal<bool> signal_tty_irq0("signal_tty_irq0"); 
-	sc_signal<bool> signal_tty_irq1("signal_tty_irq1"); 
-	sc_signal<bool> signal_tty_irq2("signal_tty_irq2"); 
-	sc_signal<bool> signal_tty_irq3("signal_tty_irq3"); 
-
-	soclib::common::Loader loader("soft/bin.soft");
-
-    soclib::common::GdbServer<soclib::common::Mips32ElIss>::set_loader(loader);
-        //                                  init_rw   init_c   tgt
-/*	soclib::caba::VciCcXCacheWrapperV1<vci_param, proc_iss > 
-	proc0("proc0", 0, maptabp, maptabc, IntTab(0),IntTab(0),IntTab(0),4,64,16,4,64,16);
-
-	soclib::caba::VciCcXCacheWrapperV1<vci_param, proc_iss > 
-	proc1("proc1", 1, maptabp, maptabc, IntTab(1),IntTab(1),IntTab(1),4,64,16,4,64,16);
-
-	soclib::caba::VciCcXCacheWrapperV1<vci_param, proc_iss > 
-	proc2("proc2", 2, maptabp, maptabc, IntTab(2),IntTab(2),IntTab(2),4,64,16,4,64,16);
-
-	soclib::caba::VciCcXCacheWrapperV1<vci_param, proc_iss > 
-	proc3("proc3", 3, maptabp, maptabc, IntTab(3),IntTab(3),IntTab(3),4,64,16,4,64,16);
-*/
-
-	soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > 
-	proc0("proc0", 0, maptabp, maptabc, IntTab(0),IntTab(0),IntTab(0),1,8,16,1,8,16);
-
-	soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > 
-	proc1("proc1", 1, maptabp, maptabc, IntTab(1),IntTab(1),IntTab(1),1,8,16,1,8,16);
-
-	soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > 
-	proc2("proc2", 2, maptabp, maptabc, IntTab(2),IntTab(2),IntTab(2),1,8,16,1,8,16);
-
-	soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > 
-	proc3("proc3", 3, maptabp, maptabc, IntTab(3),IntTab(3),IntTab(3),1,8,16,1,8,16);
-
+	sc_signal<bool> * signal_tty_irq = soclib::common::alloc_elems<sc_signal<bool> >("signal_tty_irq", nb_proc);
+
+	soclib::common::Loader loader(soft);
+
+        soclib::common::GdbServer<soclib::common::Mips32ElIss>::set_loader(loader);
+
+	soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > * proc [nb_proc];
+        for (uint32_t i=0; i<nb_proc; ++i)
+          {
+            std::ostringstream str;
+            str << "proc_" << i;
+
+            proc[i] = new soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > (str.str().c_str(), i, maptabp, maptabc, IntTab(i),IntTab(i),IntTab(i)
+#if USE_OLD_XCACHE
+                                                                                    ,iways, isets, iwords
+                                                                                    ,dways, dsets, dwords
+#else
+                                                                                    ,iways, isets, iwords
+                                                                                    ,dways, dsets, dwords
+                                                                                    ,wnwords, wnlines, wtimeout
+#endif
+                                                                                    );
+
+#if not USE_OLD_XCACHE
+            proc[i]->stop_simulation(STOP_SIMULATION_NB_FRZ_CYCLES);
+#endif
+          }
 
 	soclib::caba::VciSimpleRam<vci_param> 
-	rom("rom", IntTab(0), maptabp, loader);
+	rom ("rom", IntTab(0), maptabp, loader);
 
 	soclib::caba::VciSimpleRam<vci_param> 
 	xram("xram", IntTab(0), maptabx, loader);
 
-        //                                  x_init    c_init    p_tgt     c_tgt
+        //                                  x_init    c_init          p_tgt     c_tgt
 	soclib::caba::VciMemCacheV4<vci_param> 
-	//memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(4),IntTab(2), IntTab(4),16,256,16);
-	//memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(4),IntTab(2), IntTab(4),4,16,16);
-	memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(4),IntTab(2), IntTab(4),4,4,16);
+          memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(nb_proc),IntTab(2),IntTab(nb_proc), memc_nways, memc_nsets, memc_words, memc_heap_size);
+
+        std::vector<std::string> tty_name;
+        for (uint32_t i=0; i<nb_proc; ++i)
+          {
+            std::ostringstream str;
+            str << "tty_" << i;
+
+            tty_name.push_back(str.str());
+          }
 	
 	soclib::caba::VciMultiTty<vci_param> 
-	tty("tty",IntTab(1),maptabp,"tty0","tty1","tty2","tty3",NULL);
-
-#ifdef VCI_LOGGER
-  soclib::caba::VciLogger<vci_param> vci_logger0("vci_logger0",maptabp);
+	tty("tty",IntTab(1),maptabp,tty_name);
+
+        soclib::caba::VciXicu<vci_param> 
+        xicu("xicu", maptabp, IntTab(3), PARAM_XICU);
+
+	// soclib::caba::VciTimer<vci_param> 
+        // timer("timer", IntTab(3), maptabp, nb_proc);
+
+	soclib::caba::VciSimhelper<vci_param> 
+        simhelper("simhelper", IntTab(4), maptabp);
+
+        //                  initiatior | target 
+        // interconnect_p : proc       | rom, tty, memc, xicu, simhelper
+        // interconnect_c : proc, memc | proc, memc
+        // interconnect_x : memc       | xram
+
+#if USE_VGMN
+	soclib::caba::VciVgmn<vci_param> 
+        interconnect_p("interconnect_p",maptabp, nb_proc  , 5        , PARAM_VGMN_P);
+
+	soclib::caba::VciVgmn<vci_param> 
+        interconnect_c("interconnect_c",maptabc, nb_proc+1, nb_proc+1, PARAM_VGMN_C);
+
+	soclib::caba::VciVgmn<vci_param> 
+        interconnect_x("interconnect_x",maptabx, 1        , 1        , PARAM_VGMN_X);
+#else
+	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33> 
+	interconnect_p("interconnect_p",maptabp, IntTab(), PARAM_RING_P,nb_proc  , 5        );
+
+	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33>
+	interconnect_c("interconnect_c",maptabc, IntTab(), PARAM_RING_C,nb_proc+1, nb_proc+1);
+
+	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33>
+	interconnect_x("interconnect_x",maptabx, IntTab(), PARAM_RING_X,1        , 1        );
 #endif
-#ifdef USE_VGMN
-	soclib::caba::VciVgmn<vci_param> 
-	ringp("ringp",maptabp, 4, 3, 1, 8);
-
-	soclib::caba::VciVgmn<vci_param> 
-	ringc("ringc",maptabc, 5, 5, 1, 8);
-
-	soclib::caba::VciVgmn<vci_param> 
-	ringx("ringx",maptabx, 1, 1, 2, 8);
-#else
-
-	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33> 
-	ringp("ringp",maptabp, IntTab(), 2, 4, 3);
-
-	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33> 
-	ringc("ringc",maptabc, IntTab(), 2, 5, 5);
-
-	soclib::caba::VciSimpleRingNetwork2<vci_param,37,33> 
-	ringx("ringx",maptabx, IntTab(), 2, 1, 1);
-#endif
+
 	// Net-List
- 
-	proc0.p_clk(signal_clk);  
-	proc0.p_resetn(signal_resetn);  
-	proc0.p_irq[0](signal_proc0_it0); 
-	proc0.p_irq[1](signal_proc0_it1); 
-	proc0.p_irq[2](signal_proc0_it2); 
-	proc0.p_irq[3](signal_proc0_it3); 
-	proc0.p_irq[4](signal_proc0_it4); 
-	proc0.p_irq[5](signal_proc0_it5); 
-	proc0.p_vci_ini_rw(signal_vci_ini_rw_proc0);
-	proc0.p_vci_ini_c(signal_vci_ini_c_proc0);
-	proc0.p_vci_tgt(signal_vci_tgt_proc0);
-
-	proc1.p_clk(signal_clk);  
-	proc1.p_resetn(signal_resetn);  
-	proc1.p_irq[0](signal_proc1_it0); 
-	proc1.p_irq[1](signal_proc1_it1); 
-	proc1.p_irq[2](signal_proc1_it2); 
-	proc1.p_irq[3](signal_proc1_it3); 
-	proc1.p_irq[4](signal_proc1_it4); 
-	proc1.p_irq[5](signal_proc1_it5); 
-	proc1.p_vci_ini_rw(signal_vci_ini_rw_proc1);
-	proc1.p_vci_ini_c(signal_vci_ini_c_proc1);
-	proc1.p_vci_tgt(signal_vci_tgt_proc1);
-
-	proc2.p_clk(signal_clk);  
-	proc2.p_resetn(signal_resetn);  
-	proc2.p_irq[0](signal_proc2_it0); 
-	proc2.p_irq[1](signal_proc2_it1); 
-	proc2.p_irq[2](signal_proc2_it2); 
-	proc2.p_irq[3](signal_proc2_it3); 
-	proc2.p_irq[4](signal_proc2_it4); 
-	proc2.p_irq[5](signal_proc2_it5); 
-	proc2.p_vci_ini_rw(signal_vci_ini_rw_proc2);
-	proc2.p_vci_ini_c(signal_vci_ini_c_proc2);
-	proc2.p_vci_tgt(signal_vci_tgt_proc2);
-
-	proc3.p_clk(signal_clk);  
-	proc3.p_resetn(signal_resetn);  
-	proc3.p_irq[0](signal_proc3_it0); 
-	proc3.p_irq[1](signal_proc3_it1); 
-	proc3.p_irq[2](signal_proc3_it2); 
-	proc3.p_irq[3](signal_proc3_it3); 
-	proc3.p_irq[4](signal_proc3_it4); 
-	proc3.p_irq[5](signal_proc3_it5); 
-	proc3.p_vci_ini_rw(signal_vci_ini_rw_proc3);
-	proc3.p_vci_ini_c(signal_vci_ini_c_proc3);
-	proc3.p_vci_tgt(signal_vci_tgt_proc3);
+        for (uint32_t i=0; i<nb_proc; ++i)
+          {
+            proc[i]->p_clk(signal_clk);  
+            proc[i]->p_resetn(signal_resetn);  
+            proc[i]->p_irq[0](signal_proc_it[i][0]); 
+            proc[i]->p_irq[1](signal_proc_it[i][1]); 
+            proc[i]->p_irq[2](signal_proc_it[i][2]); 
+            proc[i]->p_irq[3](signal_proc_it[i][3]); 
+            proc[i]->p_irq[4](signal_proc_it[i][4]); 
+            proc[i]->p_irq[5](signal_proc_it[i][5]); 
+            proc[i]->p_vci_ini_rw(signal_vci_ini_rw_proc[i]);
+            proc[i]->p_vci_ini_c(signal_vci_ini_c_proc[i]);
+            proc[i]->p_vci_tgt(signal_vci_tgt_proc[i]);
+          }
 
 	rom.p_clk(signal_clk);
@@ -259,17 +347,22 @@
 	rom.p_vci(signal_vci_tgt_rom);
 
-#ifdef VCI_LOGGER
-  vci_logger0.p_clk(signal_clk);
-  vci_logger0.p_resetn(signal_resetn);
-  vci_logger0.p_vci(signal_vci_ini_rw_proc2);
-#endif
-
 	tty.p_clk(signal_clk);
 	tty.p_resetn(signal_resetn);
 	tty.p_vci(signal_vci_tgt_tty);
-	tty.p_irq[0](signal_tty_irq0); 
-	tty.p_irq[1](signal_tty_irq1); 
-	tty.p_irq[2](signal_tty_irq2); 
-	tty.p_irq[3](signal_tty_irq3); 
+        for (uint32_t i=0; i<nb_proc; ++i)
+          tty.p_irq[i](signal_tty_irq[i]); 
+
+        xicu.p_clk(signal_clk);
+        xicu.p_resetn(signal_resetn);
+        xicu.p_vci(signal_vci_tgt_xicu);
+        for (uint32_t i=0; i<nb_proc; ++i)
+        {
+          xicu.p_hwi[i](signal_tty_irq[i]);
+          xicu.p_irq[i](signal_proc_it[i][0]); 
+        }
+
+        simhelper.p_clk(signal_clk);
+        simhelper.p_resetn(signal_resetn);
+        simhelper.p_vci(signal_vci_tgt_simhelper);
 
 	memc.p_clk(signal_clk);
@@ -281,83 +374,37 @@
 
 	xram.p_clk(signal_clk);
-  xram.p_resetn(signal_resetn);
+	xram.p_resetn(signal_resetn);
 	xram.p_vci(signal_vci_tgt_xram);
-	
-	ringp.p_clk(signal_clk);
-	ringp.p_resetn(signal_resetn);
-
-	ringc.p_clk(signal_clk);
-	ringc.p_resetn(signal_resetn);
-
-	ringx.p_clk(signal_clk);
-	ringx.p_resetn(signal_resetn);
-
-	ringp.p_to_initiator[0](signal_vci_ini_rw_proc0);
-	ringp.p_to_initiator[1](signal_vci_ini_rw_proc1);
-	ringp.p_to_initiator[2](signal_vci_ini_rw_proc2);
-	ringp.p_to_initiator[3](signal_vci_ini_rw_proc3);
-
-	ringc.p_to_initiator[4](signal_vci_ini_memc);
-	ringc.p_to_initiator[0](signal_vci_ini_c_proc0);
-	ringc.p_to_initiator[1](signal_vci_ini_c_proc1);
-	ringc.p_to_initiator[2](signal_vci_ini_c_proc2);
-	ringc.p_to_initiator[3](signal_vci_ini_c_proc3);
-
-	ringx.p_to_initiator[0](signal_vci_ixr_memc);
-
-	ringp.p_to_target[0](signal_vci_tgt_rom);
-	ringp.p_to_target[1](signal_vci_tgt_tty);
-	ringp.p_to_target[2](signal_vci_tgt_memc);
-
-	ringc.p_to_target[0](signal_vci_tgt_proc0);
-	ringc.p_to_target[1](signal_vci_tgt_proc1);
-	ringc.p_to_target[2](signal_vci_tgt_proc2);
-	ringc.p_to_target[3](signal_vci_tgt_proc3);
-	ringc.p_to_target[4](signal_vci_tgt_cleanup_memc);
-
-	ringx.p_to_target[0](signal_vci_tgt_xram);
-
-	int ncycles;
-
-#ifndef SOCVIEW
-/*	if (argc == 2) {
-		ncycles = std::atoi(argv[1]);
-	} else {
-		std::cerr
-			<< std::endl
-			<< "The number of simulation cycles must "
-			   "be defined in the command line"
-			<< std::endl;
-		exit(1);
-	}
-*/
-	sc_start(sc_core::sc_time(0, SC_NS));
-	signal_resetn = false;
-
-	sc_start(sc_core::sc_time(1, SC_NS));
-	signal_resetn = true;
-
-/*
-  while(1){
-    char buf[2];
-	  std::cin.getline(buf,1);
-		sc_start(sc_core::sc_time(1, SC_NS));
-  }
-*/
-
-	for (int i = 0; ; i+=10000) {
-		sc_start(sc_core::sc_time(10000, SC_NS));
-//		proc0.print_stats();
-//		memc.print_stats();
-	}
-
-        std::cout << "Hit ENTER to end simulation" << std::endl;
-        char buf[1];
-
-	std::cin.getline(buf,1);
-
-	return EXIT_SUCCESS;
-#else
-	ncycles = 1;
+        
+	interconnect_p.p_clk(signal_clk);
+	interconnect_p.p_resetn(signal_resetn);
+
+        for (uint32_t i=0; i<nb_proc; ++i)
+        interconnect_p.p_to_initiator[i](signal_vci_ini_rw_proc[i]);
+
+	interconnect_p.p_to_target[0](signal_vci_tgt_rom);
+	interconnect_p.p_to_target[1](signal_vci_tgt_tty);
+	interconnect_p.p_to_target[2](signal_vci_tgt_memc);
+	interconnect_p.p_to_target[3](signal_vci_tgt_xicu);
+	interconnect_p.p_to_target[4](signal_vci_tgt_simhelper);
+
+	interconnect_c.p_clk(signal_clk);
+	interconnect_c.p_resetn(signal_resetn);
+
+        for (uint32_t i=0; i<nb_proc; ++i)
+	interconnect_c.p_to_initiator[i](signal_vci_ini_c_proc[i]);
+	interconnect_c.p_to_initiator[nb_proc](signal_vci_ini_memc);
+
+        for (uint32_t i=0; i<nb_proc; ++i)
+	interconnect_c.p_to_target[i](signal_vci_tgt_proc[i]);
+	interconnect_c.p_to_target[nb_proc](signal_vci_tgt_cleanup_memc);
+
+	interconnect_x.p_clk(signal_clk);
+	interconnect_x.p_resetn(signal_resetn);
+
+	interconnect_x.p_to_initiator[0](signal_vci_ixr_memc);
+
+	interconnect_x.p_to_target[0](signal_vci_tgt_xram);
+
 	sc_start(sc_core::sc_time(0, SC_NS));
 	signal_resetn = false;
@@ -365,19 +412,55 @@
 	signal_resetn = true;
 
+#if SOCVIEW
 	debug();
+#elif DEBUG_TOP
+        for (int32_t i=0; i<ncycles; ++i)
+          {
+            std::cout << std::endl
+                      << std::dec << "===== [ cycle " << i << " ]======" << std::endl
+                      << std::endl;
+            
+            sc_start(sc_core::sc_time(1, SC_NS));
+            
+            // for (uint32_t i=0; i<nb_proc; ++i)
+            //   proc[i]->print_trace(1);
+          }
+#else
+        if (ncycles==-1)
+          sc_start();
+        else
+          sc_start(sc_core::sc_time(ncycles, SC_NS));
+
+        // std::cout << "Hit ENTER to end simulation" << std::endl;
+        // char buf[1];
+	// std::cin.getline(buf,1);
+#endif
+        for (uint32_t i=0; i<nb_proc; ++i)
+          proc[i]->print_cpi();
+        for (uint32_t i=0; i<nb_proc; ++i)
+          proc[i]->print_stats();
+
+        soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_tty_irq         , nb_proc);
+	soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_tgt_proc    , nb_proc);
+	soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_ini_c_proc  , nb_proc);
+	soclib::common::dealloc_elems<soclib::caba::VciSignals<vci_param> >(signal_vci_ini_rw_proc , nb_proc);
+	soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_proc_it         , nb_proc, 6);
+
+        for (uint32_t i=0; i<nb_proc; ++i)
+          delete proc[i];
+
 	return EXIT_SUCCESS;
-#endif
 }
 
 int sc_main (int argc, char *argv[])
 {
-	try {
-		return _main(argc, argv);
-	} catch (std::exception &e) {
-		std::cout << e.what() << std::endl;
-	} catch (...) {
-		std::cout << "Unknown exception occured" << std::endl;
-		throw;
-	}
-	return 1;
+  try {
+    return _main(argc, argv);
+  } catch (std::exception &e) {
+    std::cout << e.what() << std::endl;
+  } catch (...) {
+    std::cout << "Unknown exception occured" << std::endl;
+    throw;
+  }
+  return 1;
 }
