Index: trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp
===================================================================
--- trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp	(revision 137)
+++ trunk/platforms/caba-ring-ccxcachev4_memcachev4-mips32el/top.cpp	(revision 140)
@@ -31,12 +31,15 @@
 #  define PARAM_VCI                         4,8,32,1,1,1,8,4,4,1
 
+#  define USE_OLD_XCACHE                    0
+#  define USE_VGMN                          1
 #  define NB_PROC_MIN                       1
 #  define NB_PROC_MAX                       15
-//                                          min_latency, fifo_depth
+//                                          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
+#  define PARAM_XICU                        nb_proc*nb_cpu_by_cache, nb_proc*nb_cpu_by_cache, 0  , nb_proc*nb_cpu_by_cache
+//#define PARAM_XICU                        nb_proc, nb_proc, 0  , nb_proc
 
 // * Debug
@@ -46,5 +49,5 @@
                                             
 // * Simulation                             
-#  define FILE_DEFAULT                      "configuration/default.cfg"
+#  define CONFIG_DEFAULT                      "configuration/default.cfg"
 #  define NCYCLES_DEFAULT                   0
 #  define SOFT_DEFAULT                      "soft/bin.soft"
@@ -53,8 +56,17 @@
 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))" << std::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))" << std::endl;
-  std::cout << " * soft     : software executed by this platforms. (default : \"" << SOFT_DEFAULT << "\")" << std::endl;
+  std::cout << funcname << " [option] " << std::endl;
+  std::cout << " * -NCYCLES int : number of simulated cycle, if 0 then no stop condition." << std::endl;
+  std::cout << "                  default : " << NCYCLES_DEFAULT << " cycle(s)" << std::endl;
+  std::cout << " * -CFG string  : configuration file" << std::endl;
+  std::cout << "                    - nb_proc," << std::endl;
+  std::cout << "                    - nb_cpu_by_cache, nb_dcache," << std::endl;
+  std::cout << "                    - iways, isets, iwords," << std::endl;
+  std::cout << "                    - dways, dsets, dwords," << std::endl;
+  std::cout << "                    - wnwords, wnlines, wtimeout," << std::endl;
+  std::cout << "                    - memc_nways, memc_nsets, memc_words, memc_heap_size." << std::endl;
+  std::cout << "                  default : \"" << CONFIG_DEFAULT << "\"" << std::endl;
+  std::cout << " * -SOFT string : software executed by this platform." << std::endl;
+  std::cout << "                  default : \"" << SOFT_DEFAULT << "\"" << std::endl;
 
   exit(1);
@@ -63,23 +75,39 @@
 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;
+	int    ncycles = NCYCLES_DEFAULT;
+	char * config  = CONFIG_DEFAULT;
+        char * soft    = SOFT_DEFAULT;
+
+        if (argc > 1)
+          {
+            for( int n=1 ; n<argc ; n=n+2 )
+              {
+                if( (strcmp(argv[n],"-NCYCLES") == 0) && (n+1<argc) )
+                  {
+                    ncycles = atoi(argv[n+1]);
+                  }
+                else if( (strcmp(argv[n],"-CFG") == 0) && (n+1<argc) )
+                  {
+                    // strcpy(config, argv[n+1]);
+                    config = argv[n+1];
+                  }
+                else if( (strcmp(argv[n],"-SOFT") == 0) && (n+1<argc) )
+                  {
+                    // strcpy(soft, argv[n+1]);
+                    soft = argv[n+1];
+                  }
+                else
+                  {
+                    usage(argv[0]);
+                  }
+              }
+          }
 
         if (ncycles == 0)
           ncycles = -1;
-#endif
 
         uint32_t nb_proc;
+        uint32_t nb_cpu_by_cache;
+        uint32_t nb_dcache;
         uint32_t iways, isets, iwords;
         uint32_t dways, dsets, dwords;
@@ -88,5 +116,5 @@
 
         std::ifstream inFile;
-        const char * filename = (argc>=3)?argv[2]:FILE_DEFAULT;
+        const char * filename = config;
 
         inFile.open(filename);
@@ -102,4 +130,8 @@
         nb_proc         =std::atoi(str.c_str());
         if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        nb_cpu_by_cache =std::atoi(str.c_str());
+        if (not (inFile >> str)){std::cout << "Invalid parameters number in configuration file." << std::endl; usage(argv[0]);}
+        nb_dcache       =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]);}
@@ -128,6 +160,6 @@
         memc_heap_size  =std::atoi(str.c_str());
 
-        if ((nb_proc<NB_PROC_MIN) or
-            (nb_proc>NB_PROC_MAX))
+        if (((nb_proc*nb_cpu_by_cache)<NB_PROC_MIN) or
+            ((nb_proc*nb_cpu_by_cache)>NB_PROC_MAX))
           {
             std::cout << "Parameters nb_proc is out of bound." << std::endl;
@@ -135,13 +167,8 @@
           }
 
-        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 << "    * nb_cpu_by_cache  : " << nb_cpu_by_cache  << std::endl;
+        std::cout << "    * nb_dcache        : " << nb_dcache        << std::endl;
         std::cout << "    * iways            : " << iways            << std::endl;
         std::cout << "    * isets            : " << isets            << std::endl;
@@ -180,5 +207,6 @@
 	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("mc_u"     , MC_U_BASE     , MC_U_SIZE     , IntTab(2), false));
+      //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));
@@ -187,4 +215,11 @@
 
         soclib::common::MappingTable maptabc(32, IntTab(8), IntTab(8), 0x00300000);
+        // for (uint32_t i=0; i<nb_proc; ++i)
+        //   for (uint32_t j=0; j<nb_cpu_by_cache; ++j)
+        //   {
+        //     std::ostringstream str;
+        //     str << "c_proc_" << i << "_" << j;
+        //     maptabc.add(Segment(str.str().c_str(), C_PROC_BASE+(i*nb_cpu_by_cache+j)*C_PROC_SPAN, C_PROC_SIZE , IntTab(i), false, true, IntTab(i)));
+        //   }
         for (uint32_t i=0; i<nb_proc; ++i)
         {
@@ -195,8 +230,9 @@
 	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("mc_u"    , MC_U_BASE  , MC_U_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));
+      //maptabc.add(Segment("ptba"    , PTD_ADDR   , TAB_SIZE    , IntTab(nb_proc), false, false));
 
 	std::cout << maptabc << std::endl;
@@ -204,4 +240,5 @@
 	soclib::common::MappingTable maptabx(32, IntTab(8), IntTab(8), 0x00300000);
 	maptabx.add(Segment("xram" , MC_M_BASE , MC_M_SIZE , IntTab(0), false));
+	// maptabx.add(Segment("uram" , MC_U_BASE , MC_U_SIZE , IntTab(0), false));
 	maptabx.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(0), false));
 	maptabx.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(0), false));
@@ -215,5 +252,5 @@
 	sc_signal<bool> signal_resetn("resetn");
    
-	sc_signal<bool> ** signal_proc_it = soclib::common::alloc_elems<sc_signal<bool> >("proc_it", nb_proc, 6);
+	sc_signal<bool> *** signal_proc_it = soclib::common::alloc_elems<sc_signal<bool> >("proc_it", nb_proc, nb_cpu_by_cache, 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);
@@ -236,5 +273,5 @@
 	soclib::caba::VciSignals<vci_param> signal_vci_tgt_cleanup_memc("vci_tgt_cleanup_memc");
 
-	sc_signal<bool> * signal_tty_irq = soclib::common::alloc_elems<sc_signal<bool> >("signal_tty_irq", nb_proc);
+	sc_signal<bool> ** signal_tty_irq = soclib::common::alloc_elems<sc_signal<bool> >("signal_tty_irq", nb_proc, nb_cpu_by_cache);
 
 	soclib::common::Loader loader(soft);
@@ -245,11 +282,20 @@
         for (uint32_t i=0; i<nb_proc; ++i)
           {
+            uint32_t num_cpu = i*nb_cpu_by_cache;
+
             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)
+            str << "proc_" << num_cpu;
+
+            proc[i] = new soclib::caba::VciCcXCacheWrapperV4<vci_param, proc_iss > (str.str().c_str(), num_cpu, maptabp, maptabc, IntTab(i),IntTab(i),IntTab(i)
+#if USE_OLD_XCACHE
                                                                                     ,iways, isets, iwords
                                                                                     ,dways, dsets, dwords
-                                                                                    ,wnwords, wnlines, wtimeout
+#else
+                                                                                    ,nb_cpu_by_cache   
+                                                                                    ,nb_dcache
+                                                                                    ,iways*nb_cpu_by_cache, isets, iwords
+                                                                                    ,dways*nb_cpu_by_cache, dsets, dwords
+                                                                                    ,wnwords, wnlines*nb_cpu_by_cache, wtimeout
+#endif
                                                                                     );
 
@@ -267,8 +313,8 @@
         //                                  x_init    c_init          p_tgt     c_tgt
 	soclib::caba::VciMemCacheV4<vci_param> 
-          memc("memc",maptabp,maptabc,maptabx,IntTab(0),IntTab(nb_proc),IntTab(2),IntTab(nb_proc), memc_nways, memc_nsets, memc_words, memc_heap_size);
+        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)
+        for (uint32_t i=0; i<nb_proc*nb_cpu_by_cache; ++i)
           {
             std::ostringstream str;
@@ -308,11 +354,14 @@
           {
             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_resetn(signal_resetn);
+            for (uint32_t j=0; j<nb_cpu_by_cache; ++j)
+              {
+                proc[i]->p_irq[j][0](signal_proc_it[i][j][0]);
+                proc[i]->p_irq[j][1](signal_proc_it[i][j][1]);
+                proc[i]->p_irq[j][2](signal_proc_it[i][j][2]);
+                proc[i]->p_irq[j][3](signal_proc_it[i][j][3]);
+                proc[i]->p_irq[j][4](signal_proc_it[i][j][4]);
+                proc[i]->p_irq[j][5](signal_proc_it[i][j][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]);
@@ -328,5 +377,6 @@
 	tty.p_vci(signal_vci_tgt_tty);
         for (uint32_t i=0; i<nb_proc; ++i)
-          tty.p_irq[i](signal_tty_irq[i]); 
+          for (uint32_t j=0; j<nb_cpu_by_cache; ++j)
+            tty.p_irq[i*nb_cpu_by_cache+j](signal_tty_irq[i][j]); 
 
         xicu.p_clk(signal_clk);
@@ -334,8 +384,9 @@
         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]); 
-        }
+          for (uint32_t j=0; j<nb_cpu_by_cache; ++j)
+          {
+            xicu.p_hwi[i*nb_cpu_by_cache+j](signal_tty_irq[i][j]);
+            xicu.p_irq[i*nb_cpu_by_cache+j](signal_proc_it[i][j][0]);
+          }
 
         simhelper.p_clk(signal_clk);
@@ -392,8 +443,10 @@
 	debug();
 #elif DEBUG_TOP
-        for (int32_t i=0; i<ncycles; ++i)
+
+        uint32_t num_cycle=0;
+        while(1)
           {
             std::cout << std::endl
-                      << std::dec << "===== [ cycle " << i << " ]======" << std::endl
+                      << std::dec << "===== [ cycle " << num_cycle << " ]======" << std::endl
                       << std::endl;
             
@@ -402,4 +455,5 @@
             // for (uint32_t i=0; i<nb_proc; ++i)
             //   proc[i]->print_trace(1);
+            num_cycle ++;
           }
 #else
@@ -418,9 +472,9 @@
           proc[i]->print_stats();
 
-        soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_tty_irq         , nb_proc);
+        soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_tty_irq         , nb_proc, nb_cpu_by_cache);
 	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);
+	soclib::common::dealloc_elems<sc_signal<bool>                     >(signal_proc_it         , nb_proc, nb_cpu_by_cache, 6);
 
         for (uint32_t i=0; i<nb_proc; ++i)
