Index: trunk/platforms/tsar_generic_xbar/top.cpp
===================================================================
--- trunk/platforms/tsar_generic_xbar/top.cpp	(revision 493)
+++ trunk/platforms/tsar_generic_xbar/top.cpp	(revision 504)
@@ -98,6 +98,6 @@
 ///////////////////////////////////////////////////
 
-//#define USE_ALMOS 
-#define USE_GIET 
+#define USE_ALMOS 1
+//#define USE_GIET 
 
 #ifdef USE_ALMOS
@@ -116,5 +116,5 @@
 //               Parallelisation
 ///////////////////////////////////////////////////
-#define USE_OPENMP               0
+#define USE_OPENMP 0
 
 #if USE_OPENMP
@@ -123,5 +123,5 @@
 
 //  cluster index (computed from x,y coordinates)
-#define cluster(x,y)   (y + YMAX*x)
+#define cluster(x,y)   (y + YMAX * x)
 
 ///////////////////////////////////////////////////////////
@@ -139,6 +139,11 @@
 #define vci_cell_width_ext    8
 
+#ifdef USE_ALMOS
+#define vci_address_width     32
+#endif
+#ifdef USE_GIET
+#define vci_address_width     40
+#endif
 #define vci_plen_width        8
-#define vci_address_width     40
 #define vci_rerror_width      1
 #define vci_clen_width        1
@@ -224,5 +229,5 @@
 //////////////////////i/////////////////////////////////////
 
-#define MAX_FROZEN_CYCLES     10000
+#define MAX_FROZEN_CYCLES     100000
 
 /////////////////////////////////////////////////////////
@@ -240,5 +245,5 @@
 
 #define FBUF_BASE       0x00B2000000      
-#define FBUF_SIZE       FBUF_X_SIZE * FBUF_Y_SIZE * 2
+#define FBUF_SIZE       (FBUF_X_SIZE * FBUF_Y_SIZE * 2)
 
 #define BDEV_BASE       0x00B3000000      
@@ -260,8 +265,18 @@
 #define MEMC_SIZE       0x0010000000   // 256 Mbytes per cluster
 
-#define XICU_BASE       0x00B0000000      
+#ifdef USE_ALMOS
+   #define XICU_BASE    0x0030000000
+#endif
+#ifdef USE_GIET
+   #define XICU_BASE    0x00B0000000
+#endif
 #define XICU_SIZE       0x0000001000   // 4 Kbytes
 
-#define MDMA_BASE       0x00B1000000      
+#ifdef USE_ALMOS
+   #define MDMA_BASE    0x0031000000
+#endif
+#ifdef USE_GIET
+   #define MDMA_BASE    0x00B1000000
+#endif
 #define MDMA_SIZE       0x0000001000 * NB_DMA_CHANNELS  // 4 Kbytes per channel  
 
@@ -281,4 +296,6 @@
 #define CDMA_TGTID      8
 
+bool stop_called = false;
+
 /////////////////////////////////
 int _main(int argc, char *argv[])
@@ -291,5 +308,5 @@
    char     soft_name[256]   = soft_pathname;      // pathname to binary code
 #endif
-   uint64_t ncycles          = 1000000000;         // simulated cycles
+   uint64_t ncycles          = 0xFFFFFFFFFFFFFFFF; // simulated cycles
    char     disk_name[256]   = BDEV_IMAGE_NAME;    // pathname to the disk image
    char     nic_rx_name[256] = NIC_RX_NAME;        // pathname to the rx packets file
@@ -302,5 +319,5 @@
    uint32_t debug_from       = 0;                  // trace start cycle
    uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;  // monitoring frozen processor
-   size_t   cluster_io_id    = 0;                  // index of cluster containing IOs
+   size_t   cluster_io_id;                         // index of cluster containing IOs
    struct   timeval t1,t2;
    uint64_t ms1,ms2;
@@ -311,9 +328,9 @@
       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],"-SOFT") == 0) && (n+1<argc) )
+         if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc))
+         {
+            ncycles = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-SOFT") == 0) && (n + 1 < argc))
          {
 #ifdef USE_ALMOS
@@ -321,40 +338,40 @@
 #endif
 #ifdef USE_GIET
-            strcpy(soft_name, argv[n+1]);
-#endif
-         }
-         else if ((strcmp(argv[n],"-DISK") == 0) && (n+1<argc) )
-         {
-            strcpy(disk_name, argv[n+1]);
-         }
-         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n+1<argc) )
+            strcpy(soft_name, argv[n + 1]);
+#endif
+         }
+         else if ((strcmp(argv[n],"-DISK") == 0) && (n + 1 < argc))
+         {
+            strcpy(disk_name, argv[n + 1]);
+         }
+         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc))
          {
             debug_ok = true;
-            debug_from = atoi(argv[n+1]);
-         }
-         else if ((strcmp(argv[n],"-MEMCID") == 0) && (n+1<argc) )
-         {
-            debug_memc_id = atoi(argv[n+1]);
-            assert( (debug_memc_id < (XMAX*YMAX) ) && 
+            debug_from = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc))
+         {
+            debug_memc_id = atoi(argv[n + 1]);
+            assert((debug_memc_id < (XMAX * YMAX)) && 
                    "debug_memc_id larger than XMAX * YMAX" );
          }
-         else if ((strcmp(argv[n],"-PROCID") == 0) && (n+1<argc) )
-         {
-            debug_proc_id = atoi(argv[n+1]);
-            assert( (debug_proc_id < (XMAX * YMAX * NB_PROCS_MAX) ) && 
-                   "debug_proc_id larger than XMAX * YMAX * NB_PROCS" );
-         }
-         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n+1) < argc))
-         {
-            threads_nr = atoi(argv[n+1]);
+         else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc))
+         {
+            debug_proc_id = atoi(argv[n + 1]);
+            assert((debug_proc_id < (XMAX * YMAX * NB_PROCS_MAX)) && 
+                   "debug_proc_id larger than XMAX * YMAX * NB_PROCS");
+         }
+         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc))
+         {
+            threads_nr = atoi(argv[n + 1]);
             threads_nr = (threads_nr < 1) ? 1 : threads_nr;
          }
-         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n+1 < argc))
-         {
-            frozen_cycles = atoi(argv[n+1]);
-         }
-         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n+1 < argc))
-         {
-            debug_period = atoi(argv[n+1]);
+         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc))
+         {
+            frozen_cycles = atoi(argv[n + 1]);
+         }
+         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n + 1 < argc))
+         {
+            debug_period = atoi(argv[n + 1]);
          }
          else
@@ -401,6 +418,12 @@
 #ifdef USE_GIET
     assert( (vci_address_width == 40) and
-            "VCI address width must be 40 bits" );
-#endif
+            "VCI address width with the GIET must be 40 bits" );
+#endif
+
+#ifdef USE_ALMOS
+    assert( (vci_address_width == 32) and
+            "VCI address width with ALMOS must be 32 bits" );
+#endif
+
 
     std::cout << std::endl;
@@ -454,5 +477,5 @@
    else if (XMAX <= 4) x_width = 2;
    else if (XMAX <= 8) x_width = 3;
-   else                     x_width = 4;
+   else                x_width = 4;
 
    if      (YMAX == 1) y_width = 0;
@@ -460,5 +483,12 @@
    else if (YMAX <= 4) y_width = 2;
    else if (YMAX <= 8) y_width = 3;
-   else                     y_width = 4;
+   else                y_width = 4;
+
+
+#ifdef USE_ALMOS
+   cluster_io_id = 0xbfc00000 >> (vci_address_width - x_width - y_width); // index of cluster containing IOs
+#else
+   cluster_io_id = 0;
+#endif
 
    /////////////////////
@@ -808,5 +838,5 @@
    }
 
-   for (uint64_t n = 1; n < ncycles; n++)
+   for (uint64_t n = 1; n < ncycles && !stop_called; n++)
    {
       // Monitor a specific address for L1 & L2 caches
@@ -823,7 +853,7 @@
          }
 
-         ms1 = (uint64_t)t1.tv_sec * 1000ULL + (uint64_t)t1.tv_usec / 1000;
-         ms2 = (uint64_t)t2.tv_sec * 1000ULL + (uint64_t)t2.tv_usec / 1000;
-         std::cerr << "platform clock frequency " << (double)5000000 / (double)(ms2 - ms1) << "Khz" << std::endl;
+         ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000;
+         ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000;
+         std::cerr << "platform clock frequency " << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl;
 
          if (gettimeofday(&t1, NULL) != 0) 
@@ -919,9 +949,27 @@
       sc_start(sc_core::sc_time(1, SC_NS));
    }
+
+   
+   for (size_t i = 0; i  < (XMAX * YMAX); i++)
+   {
+      size_t x = i / YMAX;
+      size_t y = i % YMAX;
+      delete clusters[x][y];
+   }
+
    return EXIT_SUCCESS;
 }
 
+
+void handler(int dummy = 0) {
+   stop_called = true;
+   sc_stop();
+}
+
+
 int sc_main (int argc, char *argv[])
 {
+   signal(SIGINT, handler);
+
    try {
       return _main(argc, argv);
